I have angular2 final version. Have created a component
@Component({
selector:'artists',
template: `
<h2>Artists Information</h2>
<ul [style.display]="artists?.length>0 ? 'block':'none'">
<li ngfor="a in artists">Name: {{a?.name}} - Followers: {{a?.folloers.total}}</li>
</ul>
`
})
export class Artists{
@Input("list")
private artists:any;
}
at a later time somewhere in the program i try to dynamically load the component
@ViewChild('divBody', {read: ViewContainerRef}) private body: ViewContainerRef;
this.body.clear();
let factory = this.resolver.resolveComponentFactory(Artists);
let injector = ReflectiveInjector.fromResolvedProviders([], this.body.parentInjector);
let b= this.body.createComponent(factory,0,injector,[]);
// data is comming from an ajax call to a remote location.
b.instance.artists = data.artists.items;
b.changeDetectorRef.detectChanges();
My problem is that the Artists view is not updated and shows a blank list row instead of list of artists.
Question is what am i missing? why template is not update with data even after i call detectChanges() ????