I have main App Component, it is empty and change detection i set to OnPush.
I have another component which is placed inside App Component and this component do NOT have change detection set, so it's default.
In this component I have two simple strings, when I click on the text I want to change it.
text1 is changing as expected.
text2 is not changing in the view (it should change after modal is closed)
I would like to know the reason why text2 is not updating. When I remove OnPush from main App Component it works perfectly.
I know how to fix it, but I would like to know the reason why it is not updating, for me it should because ExampleComponent is not OnPush.
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
template: '<app-example></app-example>',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class AppComponent {}
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.scss'],
template: '<div (click)="changeText1()">{{ text1 }}</div> <div (click)="changeText2()">{{ text2 }}</div>'
})
export class ExampleComponent {
text1 = 'text1';
text2 = 'text2';
changeText1() {
text1 = 'text1 changed';
}
changeText2() {
let dialogRef = dialog.open(ExampleModal);
dialogRef.afterClosed().subscribe(() {
text2 = 'text2 changed';
});
}
}