Angular2流星从调用this.call绑定数据 [英] Angular2 Meteor Bind Data from calling this.call

查看:44
本文介绍了Angular2流星从调用this.call绑定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

方法

Meteor.methods({
    'test' : function(test: string) {
        return test;
    }
})

组件

我的班级扩展了 MeteorComponent

show: string;
constructor() {
     this.call('test', 'txt', (err, res) => {
          this.show = res
     });
}

视图

<span>{{show}}</span>

它什么也没显示,我希望它会显示"txt".

it shows nothing, as I expect it will show 'txt'.

推荐答案

autorun 不同, call 没有参数告诉它要在 NgZone ,因此Angular的更改检测不会生效.

Unlike autorun, call has no parameter to tell it to run inside the NgZone, so Angular's change-detection won't kick in.

您需要这样写:

constructor(zone: NgZone) {
  this.call('test', 'txt', (err, res) => {
    zone.run(() => {
      this.show = res;
    });
  });
}

这篇关于Angular2流星从调用this.call绑定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆