【发布时间】:2020-07-06 20:54:50
【问题描述】:
我想获取订阅的状态代码和正文。
哇,我不能。好吧,我可以但完全没用,因为我不能回来。
@Injectable()
export class ApiService {
constructor(private _http: HttpClient,
private _authHttp: HttpClient,
public jwtHelper: JwtHelperService,
private loggedinService: LoggedinService){
}
status_code:number
def test(){
var result_ = this._http.get(this.getEndpointUrl(endpoint), {headers: new HttpHeaders({ 'Content-Type': 'application/json','Authorization': localStorage.getItem('id_token') }),observe: 'response'});
result_.subscribe(resp=>{
this.status_code = resp.status
console.log(resp.status). //works
})
let wtf = result_.toPromise().then(resp => console.log('toPromise', this.status_code = resp.status));
return this.status_code. //null
}
如何等待返回?订阅完成前明确返回
【问题讨论】:
-
你真的应该更彻底地阅读文档angular.io/guide/http
标签: javascript angular typescript http rxjs