2016-06-16 10 views
1

メソッドを呼び出す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」と表示されるので、何も表示されません。角度の変化を検出がでキックしないようにautorunとは異なり、callは、NgZone内で実行するように指示するパラメータがありません

答えて

1

あなたはそれをこのように記述する必要があります。

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

@Martin C.の答えの説明を追加するだけです。

Angular2-Meteor 0.5.6では(まだNPMには公開されていません)、autoBindを使用できるはずです。

this.call('test', 'txt', (err, res) => { 
    this.show = res; 
    }, true); // set `autoBind` to `true` here 

https://github.com/Urigo/angular2-meteor/issues/279

+0

私は結果が返されたとして、([ERR、RES])を使用する必要があると思う真の値を与えた後の配列であります – Sieryuu