angular - Extend a components change detection in Angular2 -
i have list object, this
class list { private urls: string[] = []; public getnames(): observable<string[]> { // fetch `this.urls` , extract names } public addurl(url: string) { this.urls.push(url); } public hash(): string { // generate hash out of `this.urls` } }
it has urls, , can provide names found on these urls
now need component displays these names:
@component({ selector: 'lister', template: '<p *ngfor="let name of names|async">{{ name }}</p>' }) class lister implements onchanges { @input() list: list; private names: observable<string[]>; ngonchanges() { this.names = this.list.getnames(); } }
so far good, works if use this
<lister [list]="somelist"></lister>
but doesnt refresh when somelist.addurl(...)
called, due fact not change anything.
a workaround introduce changes, this:
class lister implements onchanges { // ... @input() hash: string; }
and use lister accordingly:
<lister [list]="somelist" [hash]="somelist.hash()"></lister>
but seem make unneccessary complex caller.
i'd rather somehome make lister "listen" it's lists changes.
is there way achieve this?
ok, clear case of rtfm: answer ngdocheck, called every time change detection run.
Comments
Post a Comment