我需要将角度1.x滤镜转换为角度2.0管道请帮帮我,下面是我的角度js 1.x滤镜代码
$scope.selectname1={};
$scope.selectname2={};
$scope.selectname3={};
$scope.filter1 = function(item){
return (!($scope.selectname1&&$scope.selectname1.id)||item.id !=$scope.selectname1.id);
};
$scope.filter2 = function(item){
return (!($scope.selectname2&&$scope.selectname2.id)||item.id!=$scope.selectname2.id);
};
$scope.filter3 = function(item){
return (!($scope.selectname3&&$scope.selectname3.id)||item.id !=$scope.selectname3.id);
};
答案 0 :(得分:1)
创建管道类
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
}
}
之后在组件中添加并包含管道
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 { }