Search code examples
meteorangularangular2-meteor

Angular2 Meteor Bind Data from calling this.call


Methods

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

Component

My Class extends MeteorComponent

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

view

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

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


Solution

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

    You'll need to write it this way:

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