javascript - Angular 2 not updating *sometimes* -
i have angular 4 application running on electron.
in main component run service opens saved file , sets parameters on object called 'session'.
ngoninit(): void { this.service.ready.subscribe(() => { this.session = this.service.session; console.log(this.session.name) }); this.service.startservice(); }
i either use file dialog open session file or load last session file when initializing application. update ui subscribing 'ready' event service emits when has finished loading file. note both opening recent file , loading file using dialog, runs same method.
the problem: when opening file file through dialog, ui get's updated immediately. when loading last session on startup, ui doesn't updated.
what have tried service uses ngzone trigger change detection. subscription shows correct session set variable 'this.session' have tried using changedetectorref no difference.
why there difference in change detection when use same method , event trigger it? have components still being initialized?
update show zone updating in service
from service:
loadsession(path: string): void { fs.readfile(path, { encoding: 'utf-8' }, (err, data) => { if (!err) { var session = json.parse(data); console.log(session); this.zone.run(() => { this.session = session; this.readytostart(); this.notify("opened session:", this.session.name, null); console.log("opened session"); }); } else { console.log(err); } }); }
my readytostart method emits 'ready' event
why not use loggerservice
this:
this.logger.tick_then(() => this.session = this.service.session);
this put change on next change detection cycle
Comments
Post a Comment