.pipe angular code example
Example 1: ngchange angular 8
import { Component } from '@angular/core';
@Component({
selector: 'my-app',
template: `
<input type="number" [ngModel]="percent" (ngModelChange)="onPercentChange($event)" />
`,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
percent = 20;
onPercentChange(percent: number) {
console.log('here');
this.percent = percent;
}
}
Example 2: command to create custom pipe in angular 6
ng generate pipe personName
Example 3: angular pipes
import {Pipe, PipeTransform} from '@angular/core';
@Pipe ({
name : 'sqrt'
})
export class SqrtPipe implements PipeTransform {
transform(val : number) : number {
return Math.sqrt(val);
}
}
import { SqrtPipe } from './app.sqrt';
declarations: [
SqrtPipe,
],