Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/424.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 回调函数后未更新Angular2视图_Javascript_Meteor_Angular_Meteor Slingshot - Fatal编程技术网

Javascript 回调函数后未更新Angular2视图

Javascript 回调函数后未更新Angular2视图,javascript,meteor,angular,meteor-slingshot,Javascript,Meteor,Angular,Meteor Slingshot,我使用Meteor-Angular2和slingshot包将图像上传到S3存储。从函数返回并分配给绑定字符串时,视图未更新。(setTimout函数正在工作并更新视图,但上载器函数未工作) 导出类AdminComponent{ 公共URL变量:string=“ynet.co.il”; 构造函数(){ this.uploader=newslingshot.Upload(“myfileuploades”); 设置超时(()=>{ this.urlVariable=“视图已更新”; }, 10000)

我使用Meteor-Angular2和slingshot包将图像上传到S3存储。从函数返回并分配给绑定字符串时,视图未更新。(setTimout函数正在工作并更新视图,但上载器函数未工作)

导出类AdminComponent{
公共URL变量:string=“ynet.co.il”;
构造函数(){
this.uploader=newslingshot.Upload(“myfileuploades”);
设置超时(()=>{
this.urlVariable=“视图已更新”;
}, 10000);
}
onFileDrop(文件:file):无效{
log('gotfile2');
this.uploader.send(文件,函数(错误,下载URL){
如果(错误){
//日志服务详细响应
}
否则{
this.urlVariable=“视图未更新”;
}
});
}
}
使用箭头函数(
()=>
)而不是
函数()
,以保留
的范围。

    this.uploader.send(file, (error, downloadUrl) => {
        if (error) {
            // Log service detailed response
        }
        else {
            // now `this.` points to the current class instance
            this.urlVariable = "View not updated";

        }
    });

这一款适合我:(窄功能+Ngzone)


视图仍然没有更新,除非我移动到路由器中的另一个路由或执行某些操作以刷新页面。调用
onFileDrop
的位置在哪里?谢谢!使用您的答案并添加到其中。ngZone.run(()=>{this.urlVariable=“视图未更新”;});它现在正在工作并立即更新!:-)
 this.uploader.send(file, (error, downloadUrl) => {
        if (error) {
            // Log service detailed response
        }
        else {
            // now `this.` points to the current class instance
            this._ngZone.run(() => {this.urlVariable = "View not updated"; });


        }
    });