我想在角度2中創建我的第一個自定義管道,但似乎我在代碼中缺少某些東西阻止我獲取所需的輸出:我想僅顯示類型相同的名稱以「T」或「A」:Angular2中的管道
import { Component } from '@angular/core';
import {Pipe, PipeTransform} from '@angular/core';
@Pipe({name:"search"})
export class search{
transform (value){
x = [];
x = items.filter(item => item.Type = 'T');
x = items.filter(item => item.Type = 'A');
return x;
}
}
@Component({
selector: 'my-app',
Pipes: [search],
template: `
<h1>My First Angular 2 App</h1>
<br>
<li *ngFor = "#c of todos.Name">{{c | search}}</li>
`
})
export class AppComponent {
todos = [
{"Name":"Sleep","Type":"T"},
{"Name":"Eat","Type":"E"},
{"Name":"Work","Type":"T"},
{"Name":"Jump","Type":"A"}
];
}
:( – Maryam