I'm trying to learn how use ng-template by modifying the standard stackblitz.com "Hello" project so that the Hello component is rendered by an ng-template. Unfortunately, it gets a nasty ExpressionChangedAfterItHasBeenCherredError.
Previous value: 'name: undefined'. Current value: 'name: Angular'. It seems like the view has been created after its parent and its children have been dirty checked. Has it been created in a change detection hook?
Can someone explain this can be accomplished without the error?
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
name = 'Angular';
@ViewChild('tpl') tpl;
constructor(private _vcr: ViewContainerRef) { }
ngAfterViewInit() {
this._vcr.createEmbeddedView(this.tpl);
}
}
app.component.html:
<ng-template #tpl>
<hello name="{{ name }}"></hello>
</ng-template>
The link: https://stackblitz.com/edit/angular-48ptik?file=src%2Fapp%2Fapp.component.html