这更像是一个设计问题:
我有一个 angularJS 应用程序,
这个应用程序使用服务与具有登录功能的 API 进行通信......
app.service('managerApiService', function($q){
var myApi = new WWW_Wrapper(...);
myApi.setInput('www-asynchronous', true);
var defer = $q.defer();
this.login = function(){
...
};
this.logout = function(){
...
};
this.getShops = function(){
...
return defer.promise;
}
});
和另一个处理用户登录/凭据/信息的服务:
app.service('loginService', function(){
this.credentials = {username: null, password: null };
this.loginData = null; // comes from server during login...
this.login = function(){
...
};
this.logout = function(){
...
};
});
我的问题是:
- 我应该
LoginService注入managerApiService并更新它的凭据吗? - 我应该
managerApiService注入LoginService并注意它的凭据吗? - 我应该将它们组合成一项服务吗?
还有什么想法吗?