新项目的又一个令人不安的情况:
遵循控制器代码:
(function () {
'use strict';
angular
.module('offerRequest', [])
.controller('offerRequestCtrl', offerRequestCtrl);
offerRequestCtrl.$inject = ['$scope', '$rootScope', '$location'];
function offerRequestCtrl($scope, $rootScope, $location) {
// controller code starts here.
/* jshint validthis:true */
var vm = this;
vm.title = 'offerRequestCtrl';
activate();
function activate() { }
}
})();
使用以下路由:
// state for requesting offers
.state('offerrequest', {
url: '/offerrequest',
templateUrl: 'app/components/offerrequest/offerrequest.html',
controller: 'offerRequestCtrl'
})
导致以下错误消息:
Argument 'offerRequestCtrl' is not a function, got undefined
尝试了旧的定义方式:
angular.module('offerRequest', [])
.controller('offerRequestCtrl', function offerRequestCtrl() {
});
引发同样的错误。在我想与之合作的第一个实现中,我可能做错了什么?
答案 0 :(得分:2)
您需要仅使用依赖关系声明模块全局,
angular
.module('offerRequest', [])
将控制器更改为,
angular
.module('offerRequest')
.controller('offerRequestCtrl', offerRequestCtrl);