[英]Property 'user' does not exist on type 'Object'. Angular
我正在嘗試訂閱 Angular 中的異步 function。VSCode 將subscribe
標記為已棄用 & res['user']
marks: Property 'user' does not exist on type 'Object'
。
getUser(){ this.userService.getUserProfile().subscribe( res => { this.user = res['user']; }, err => { console.log(err); } ); }
getUserProfile() { return this.http.get(this.url + '/userProfile'); }
subscribe
本身並沒有被棄用,只有您正在使用的變體被棄用。 您寧願按如下方式編寫代碼:
getUser(){
this.getUserProfile().subscribe({
next: (res) => {
this.user = res.user;
},
error: (err) => {
console.log(err);
}
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.