I,m working on a quite old project which using Angular1.5.3 and now I want to add a new component. I have configed everything as the other component, now the newpage can be display(.html wroks fine) , but the data is not loaded(controller). and I got the error:
The controller with the name 'MyPageController' is not registered
here is some code of the project:
in mypage.controller.js:
(function () {
'use strict';
angular
.module('forecastAngular')
.controller('MypageController', MypageController);
/** @ngInject */
function MyPageController($scope, $rootScope, $state, $http, $timeout, usSpinnerService, dataFactory, $q, CommonServices, baseUrl) {
...
}
and in the index.route.js:
(function () {
'use strict';
angular
.module('forecastAngular')
.config(routerConfig);
/** @ngInject */
function routerConfig($stateProvider, $urlRouterProvider) {
$stateProvider
.state('mypage', {
url: '/mypage',
views: {
'body': {
templateUrl: 'app/myPage/mypage.html',
controller: 'MypageController',
}
},
data: {
authorizedRoles: ['Admin', 'Manager', 'Director', 'Registered User', 'HR'],
menuName: "mypage",
isShowSearch: false,
isShowDomain: false
}
});
}
and I also searched for this problem , someone said inject the controller use :
angular.module('myApp', []).controller('MyController', [function() {
// ...
}]);
but I tried . not work for me . and the other component is config like what I have paste above. and it works fine.
can any one tell me how can I register the controller in right way?
The function's name is wrong.
Should be:
This function
MyPageControllerdoes not exist.