Skip to content

Instantly share code, notes, and snippets.

@AregSargsyan
Created May 30, 2020 13:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AregSargsyan/b0daa69edd7936329a88254a87a3a358 to your computer and use it in GitHub Desktop.
Save AregSargsyan/b0daa69edd7936329a88254a87a3a358 to your computer and use it in GitHub Desktop.
OnPush works when input referense changed
@Component({
selector: 'child',
template: `
<h1>{{object.name}}</h1>
{{runChangeDetection}}
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TooltipComponent {
@Input() object;
get runChangeDetection() {
console.log('Checking the view');
return true;
}
}
@Component({
selector: 'app-root',
template: `
<child [object]="object"></child>
<button (click)="onClick()">Click</button>
`
})
export class AppComponent {
object = {
name: 'Angular'
};
onClick() {
this.object.name = 'React';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment