0
在我的代码使用无极我有自定义后方法,其盘区的http类的角2.在方法返回可观察原因错误
post(url: string, body: string, options?: RequestOptionsArgs): Observable<any> {
if (!this._gs.externalRequest) {
let that = this;
this._gs.getToken().then((token) => {
if (token) {
options = this.prepareOptions(options, token);
}
return that.sendPostRequest(url, body, options);
});
}
else {
this._gs.externalRequest = false;
return this.sendPostRequest(url, body, options);
}
}
在上面的代码中交方法返回可观察到的,而该方法此。 _gs.getToken()如果条件从本地存储中读取令牌的异步调用并返回承诺。
虽然汇编doenst产生任何错误,但,当我访问
this.http.post( '/ API/myFormHandler',this.form.value) .subscribe((数据)=> { });
class MyFormComponent- inline template:16:29 caused by: Cannot read property 'subscribe' of undefined
顺便说一句,在使用胖箭头功能时,您不必使用'that = this'。 – hgoebl
'if(!...){...}'不返回任何东西。 – hgoebl