I have a angular template which contains a ng-template. I have tried to insert an embedded view via ngTemplateOutlet. However I always get the following error:
core.js:4061 ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'undefined'. Current value: '[object Object]'.
This is the part where I am trying to use ngTemplateOutlet
<ng-template [ngTemplateOutlet]="headerLogoMiniComponent?.templateRef"></ng-template>
If i remove this line, the error will fix. What should I do to solve this problem without remove the mentioned part?
I suppose that I should add a condition with *ngIf
for that wait headerLogoMiniComponent
to be loaded. (But I don't know how to do that)
The declaration looks like the following:
@Component({
selector: 'mk-layout-header-logo-mini',
template: '<ng-template #templateRef><ng-content></ng-content></ng-template>'
})
export class HeaderLogoMiniComponent {
@ViewChild('templateRef',{static: false}) public templateRef:TemplateRef<any>; }
@ContentChild(HeaderLogoMiniComponent, {static: false}) public headerLogoMiniComponent: HeaderLogoMiniComponent;