我在使用 ui-router 时遇到问题。如果我使用内联函数,它可以工作,否则当我点击路由时,控制器不会被使用。我可以调试浏览器并且 js 正在交付,但没有触及断点。
//This is the error when I go to the non working route
Error: [$injector:unpr] http://errors.angularjs.org/1.5.0/$injector/unpr?p0=Provider%20%3C-%20%20%3C-%20MainCtrl
//The commented main route works
(function(){
angular.module('invNodeServer',[
'ui.router'
])
.config(function ($stateProvider,$urlRouterProvider,$locationProvider) {
$locationProvider.html5Mode({
enabled: true,
requireBase: false
});
$urlRouterProvider.otherwise("/");
$stateProvider
.state('main', {
url: "/",
templateUrl: "app/main/main.html",
controller:'MainCtrl',
controllerAs:'vm'
})
//.state('main', {
// url: "/",
// templateUrl: "app/main/main.html",
// controller:function($scope){
// $scope.title = 'Main'
// }
//})
})
})();
// This is the controller for the non working route
(function () {
'use strict';
var controllerId = 'MainCtrl';
angular.module('invNodeServer').controller(controllerId, MainCtrl);
MainCtrl.$inject = [''];
/* @ngInject */
function MainCtrl() {
/* jshint validthis: true */
var vm = this;
vm.title = 'Main';
vm.activate = activate;
activate();
////////////////
function activate() {
}
}
})();