我在angular中得到了这个错误:
Module 'SecurityResource' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
以下是它的代码(全部)
(function(){
'use strict';
function SecurityResource($resource){
return $resource('/authenticate', {email: userName, password: password}, {
login: {
method: 'POST'
}
});
}
angular.module('Security',[])
.factory('SecurityResource', SecurityResource);
})();
与
结合使用 (function(){
'use strict';
function SecurityService(SecurityResource){
var security = {};
return {
login: function(userName, password){
SecurityResource.login({email: userName, password: password}, function(response){
if(response){
security.User = response.user;
security.BusinessUnits = response.businessUnits;
}
});
}
};
}
angular.module('Security', ['SecurityResource'])
.factory('SecurityService', SecurityService);
})();
我将它包含在index.html
中并在登录指令中注入,如此
(function () {
'use strict';
angular
.module('app', ['Security'])
.controller('LoginController', LoginController);
LoginController.$inject = ['$location', 'FlashService', 'SecurityService'];
function LoginController($location, FlashService, SecurityService) {
var vm = this;
vm.login = login;
function login() {
vm.dataLoading = true;
SecurityService.login(vm.username, vm.password);
$location.path('/');
}
})();
有人能看到这里的错误吗?看起来我没有正确地调用它。