我使用Meteor-Angular2和彈弓包將圖像上傳到S3存儲。從函數返回並分配給綁定的字符串時,視圖未更新。 (setTimout功能正在工作和更新視圖,但載功能不)Angular2視圖在回調函數後未更新
export class AdminComponent {
public urlVariable: string = "ynet.co.il";
constructor() {
this.uploader = new Slingshot.Upload("myFileUploads");
setTimeout(() => {
this.urlVariable = "View is updated";
}, 10000);
}
onFileDrop(file: File): void {
console.log('Got file2');
this.uploader.send(file, function (error, downloadUrl) {
if (error) {
// Log service detailed response
}
else {
this.urlVariable = "View not updated";
}
});
}
}
仍然不更新視圖,除非我移動到路由器中的另一條路由器或執行一些觸發頁面刷新的操作。 – roish
從哪裏調用'onFileDrop'? –
謝謝! 與你的答案和除了this._ngZone.run(()=> {this.urlVariable =「查看未更新」;});它正在工作,並立即更新! :-) – roish