我收到了以下错误
Error: [$injector:unpr] Unknown provider: AuthProvider <- Auth <- LoginCtrl
我的代码如下所示......
'use strict';
angular.module('yapp')
.controller('LoginCtrl', function($scope, $location,Auth,$log) {
$scope.submit = function(email,password) {
var model = {
email:'',
password:''
};
$scope.model = model;
Auth.login(email,password)
.then(function(token){
$log.info(token);
},function (error){
$log.info(error);
});
}
});
&#39;使用严格的&#39;;
angular.module(&#39; YAPP&#39;) .factory(&#39; Auth&#39;,功能($ http,$ q,$ log,APIHelper){
var self = this;
this.login = function(email,password){
var d = $q.defer();
var requestUrl = APIHelper.endpoints.login;
var data = {
email:email,
password:password
};
$http({
url:requestUrl,
dataType: 'json',
method: 'POST',
data:data,
headers: {
"Content-Type": "application/json"
}
})
.success(function(data,status,headers,config){
d.resolve(data);
})
.error(function(data,status,headers,config){
d.reject(data);
});
return d.promise;
}
return self;
});
答案 0 :(得分:1)
当您还没有包含已定义服务的文件时,通常会发生这种情况。你确定你为它做了一个脚本导入或一个module.export吗?