Created
May 30, 2020 13:01
-
-
Save AregSargsyan/b0daa69edd7936329a88254a87a3a358 to your computer and use it in GitHub Desktop.
OnPush works when input referense changed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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