angular - ng2 update template after making a simple meteor.call -


this has been asked before cannot find answer helps. want oresult change value after call made. answer has appropriate running ng2, meteor , angular-meteor. thanks!

/// <reference path="../../typings/angular2-meteor.d.ts" />  import {input, component, view, ngzone} 'angular2/core'; import {meteorcomponent} 'angular2-meteor';  @component({   selector: 'testcall',   template: `     <button (click)="testcall()">get testcall data</button>     <code><pre>{{oresult}}</pre></code>   ` })  export class testcall extends meteorcomponent {    oresult:any    constructor(private _ngzone: ngzone) {     super();     this.oresult = json.stringify({res: 'start'});   }    testcall(): void {     meteor.call('testcall', function(error,result) {       if (error) {         console.log('failed', error);       } else {           console.log('successful call', result);           this._ngzone.run(() => {               this.oresult = result           });       }     });   } } 

edit

i've shortened code , tried explore if 'this' problem. absence of angular-meteor component makes difference execution of meteor.call. ng2 still fails change template after call has executed. , i've tried , without ngzone. might dump ng2 'cos sure haven't brains or time stuck on trivial stuff this!

/// <reference path="../../typings/angular2-meteor.d.ts" />  import {input, component, view} 'angular2/core';  @component({   selector: 'testcall',   template: `     <button (click)="testcall()">get testcall data</button>     <code><pre>{{oresult}}</pre></code>   ` })  export class testcall {    oresult:any    testcall(): void {     meteor.call('testcall', (error:any, result:any) => error ?      console.log('failed', error) :      (this.oresult=result, console.log('successful call', result, this.oresult)));   } } 

edit

this clunky bit of code works fashion. suggest how make meteor.call callback of settimeout?

  testcall(): void {     var self:any =     meteor.call('testcall', (error:any, result:string) => error ?       console.log('failed', error) :       (self.oresult=result, console.log('successful call', self.oresult)));     settimeout(()=>{       this.oresult=self.oresult;     },2000);   } 

export class testcall extends meteorcomponent {    oresult:any    constructor(private zone: ngzone) {     super();     this.oresult = json.stringify({res: 'start'});   }    testcall(): void {     meteor.call('testcall', function(error,result) {       if (error) {         console.log('failed', error);       } else {           console.log('successful call', result);         this.zone.run(() => { // updates within angular zones            this.oresult = result         });       }     });   } } 

see triggering angular2 change detection manually


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -