Skip to content

Instantly share code, notes, and snippets.

@DmitriyRF
Created May 1, 2020 09:13
Show Gist options
  • Save DmitriyRF/d528533b551678292c5b63db6c3c474a to your computer and use it in GitHub Desktop.
Save DmitriyRF/d528533b551678292c5b63db6c3c474a to your computer and use it in GitHub Desktop.
Angular detection optimization
@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