0
我是Angular的新手,我想設置登錄表單以允許我的用戶登錄。我收到此錯誤:
Cannot read property 'setUserPass' of undefined
我有這樣的服務:
(function(){
var app = angular.module('myapp');
app.service('loginSvc',function($resource){
var username="";
var password="";
self=this;
self.setUserPass=function(user,pass){
self.username=user;
self.password=pass;
};
return $resource("http://localhost:8080/user",{},
{get: {method:'GET',
headers : { authorization : "Basic "+
btoa(self.username+":"+self.password)}}});
});
})();
,並在控制器:
var username="xxxx";
var password="xxx";
var self = this;
loginSvc().setUserPass(self.username,self.password);
self.auth = loginSvc().get();`enter code here`
我應該如何傳遞給我服務的用戶名和密碼?
是的,我認爲注射正是這樣,它的工作原理,如果我硬編碼在服務密碼和用戶名的,但:-( – max
你嘗試loginSvc.setUserPass(不帶參數運行self.username,self.password);而不是loginSvc()。setUserPass(self.username,self.password);? –
是的,但不起作用! – max