问题描述
我有一个服务类 NetworkService ,我在其中放置了所有常规的 rest api请求,例如获取,放置,发布,删除等,以及所有其他服务正在使用此 NetworkService 方法执行操作。目前,我订阅所有其他服务中的 NetworkService 方法。我想知道是否有一种更好的方法可以使我可以在组件中进行订阅,而不是在其他服务中进行订阅。例如,对于登录,我使用的是 AuthenticationService 的方法,该方法订阅是 NetworkService 的方法 :
AuthenticationService方法:
doLogin(loginData) {
let loginParams = {
client_id: "app",grant_type: "password",password: btoa(loginData.password),username: loginData.username,};
this.networkService.postGetToken(loginParams).subscribe(
(data) => {
this.onPostGetTokenSuccess(data);
},(error) => {
this.onPostGetTokenError(error);
}
);
}
NetworkService方法:
postGetToken(dataParam) {
//Used only for Login
let options = {
headers: {
"Content-Type": "application/x-www-form-urlencoded",},};
let data = { params: dataParam };
return this.http
.post(
this.baseurl +"svf/zsv/oauth/oauth20/token",data,options
)
.pipe(
map(
(data) => {},(error) => {}
)
);
}
在登录组件中,我无法订阅 AuthenticationService 的 doLogin 方法,就像在AuthenticationService中一样,我已经订阅了 > NetworkService ,很难在登录组件中获得结果。在登录组件中,我正在执行以下操作:
performlogin() {
if (!this.loginForm.valid) {
return false;
} else {
this.loaderService.showLoader();
let data = this.authenticationService.doLogin(this.loginForm.value);
if (data["access_token"]) {
} else {
}
}
}
如果有人知道更好的tpo方法,请在此处分享。谢谢
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)