我想從(Firebase)數據存儲返回的數據初始化對象的值。我可以看到正在返回的數據,但我無法將其分配給本地變量。我自學打字稿,角2和火力地堡,所以這可能是一個「杜」的問題...Angular 2構造函數ngOnInit未定義的屬性TypeScript
import ProfileProvider from ../providers/profile
@Component({...})
class Profile {
userProfile:any
constructor (public profileProvider: ProfilePRovider) {}
ngOnInit() {
this.profileProvider.getUSerProfile().on ("value", function(snap) {
console.log(snap.val()); // this works, prints all my data correctly
this.userProfile = snap.val(); // this fails, "cannot set property userProfile of undefined"
}
}
}
任何幫助表示讚賞! 謝謝!
這也是[?如何正確地做angular2打字稿一個「綁定」(https://stackoverflow.com/a/ 45136760/2545680) –