HOW TO CONVERT ANGULAR JS1.X FILTER TO ANGULAR JS 2.0 PIPES?

How to convert angular js1.x filter to angular js 2.0 pipes?

Create pipe class
import { Pipe, PipeTransform } from ‘@angular/core';
@Pipe({name: ‘filter1′})
export class ExponentialStrengthPipe implements PipeTransform {
transform(value: number, exponent: string): number {
return exponent; // do something with your vallue
}
}
After that in your component add and include pipe
import { Component } from ‘@angular/core';
import { ExponentialStrengthPipe } from ‘./exponential-strength.pipe';
@Component({
selector: ‘power-booster’,
template: `

<h2>Power Booster</h2>

<p>Super power boost: {{2 | filter1}}</p>
`,
pipes: [ExponentialStrengthPipe]
})
export class PowerBoosterComponent { }

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>