How can I access to root component for change properties?
Problem:
I have difference templates (default and for the custom page), and these templates have the different structure. I want the control to render process via the custom parameter in the class of root component (AppComponent).
As an example:
app.component.html:
<div>
<div id="wrapper">
<div *ngIf="!customPage">
<div id="page-wrapper">
<div class="container-fluid">
<router-outlet></router-outlet>
</div>
</div>
</div>
<div *ngIf="customPage">
<router-outlet></router-outlet>
</div>
</div>
</div>
app.component.ts:
export class AppComponent{
customPage: boolean;
constructor() {
this.customPage = false;
}
}
And I try to access from custom.page.ts:
export class CustomComponent implements AfterViewChecked {
constructor(private rootComponent: AppComponent) {
}
ngAfterViewChecked(): void {
this.rootComponent.customPage = true;
}
}
But I retrieve the error:
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.
I try to use other lifecycle events, but on all events, I retrieve this error.
And, I think what this solution is not good. Maybe Angular2 have solutions for this problem?
Thank.