我想在網頁Oninit後得到一個值,並且有我的代碼。從服務器獲取數據後的回調函數
ngOnInit() {
this.getVideo(this.getScore);
}
getVideo(callback) {
this.dataService.getVideo(this.videoID).subscribe(
data => this.video = data,
error => console.log(error)
);
if (typeof callback === 'function')
callback();
}
getScore() {
console.log(this.video['Score']);
}
我可以在頁面上呈現我的視頻分數,如果沒有任何錯誤,但在回調使它錯誤。
caused by: Cannot read property 'video' of undefined
如何從服務器獲取數據後獲取值?謝謝!
謝謝,這正是我需要的! – PaulHuang