Created
May 1, 2020 09:13
-
-
Save DmitriyRF/d528533b551678292c5b63db6c3c474a to your computer and use it in GitHub Desktop.
Angular detection optimization
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
@Pipe({ | |
name: 'compile' | |
}) | |
export class CompilePipe implements PipeTransform { | |
transform(value: string): string { | |
console.log('executed'); | |
return btoa(value); | |
} | |
} | |
@Component({ | |
selector: 'app-component', | |
template: ` | |
{{ name | compile }} | |
<input [(ngModel)]="value"/> | |
<button (click)="changeName()">Change the Name</button> | |
`, | |
changeDetection: ChangeDetectionStrategy.OnPush, | |
}) | |
export class DemoComponent { | |
public name = 'Bob'; | |
public value: string; | |
public changeName(): void { | |
this.name = this.value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment