我为搜索创建管道。when user select complete from selectbox it show complete products and when select the uncomplete show uncomplete product but when i use this code it not show me this Error :
未处理的承诺拒绝:模板解析错误:找不到管道“SearchCompletePipe”(“]task of tasks | SearchCompletePipe:SearchCompletePipe; let index=index”[task]="task">Loading . . .
这是我的代码:
管道 :
import { Pipe, PipeTransform } from '@angular/core';
import { Task } from '../task/task-list/task';
@Pipe({
name: 'search-complete'
})
export class SearchCompletePipe implements PipeTransform {
transform(tasks: Task[], args?: any): any {
if (!tasks) {
return tasks;
}
let complete = args[0];
return tasks.filter((task: Task) => task.complete == complete)
}
}
任务列表 :
import { Component, OnInit,Output } from '@angular/core';
import { Task } from './task';
@Component({
selector: 'app-task-list',
templateUrl: './task-list.component.html',
styleUrls: ['./task-list.component.css']
})
export class TaskListComponent implements OnInit {
complete: boolean = false;
@Output() tasks: Task[];
constructor() {
this.tasks = [
new Task(1, "Site Design", "Lorem ipsum dolor sit amet, consectetur adipisicing elit. A adipisci autem consequuntur ea exercitationem fuga, illo impedit ipsam itaque magnam mollitia nihil quam quibusdam repellendus, reprehenderit totam vel. Beatae, eum.", false),
new Task(2, "Site Design", "Lorem ipsum dolor sit amet, consectetur adipisicing elit. A adipisci autem consequuntur ea exercitationem fuga, illo impedit ipsam itaque magnam mollitia nihil quam quibusdam repellendus, reprehenderit totam vel. Beatae, eum.", false),
new Task(3, "Site Design", "Lorem ipsum dolor sit amet, consectetur adipisicing elit. A adipisci autem consequuntur ea exercitationem fuga, illo impedit ipsam itaque magnam mollitia nihil quam quibusdam repellendus, reprehenderit totam vel. Beatae, eum.", false),
new Task(4, "Site Design", "Lorem ipsum dolor sit amet, consectetur adipisicing elit. A adipisci autem consequuntur ea exercitationem fuga, illo impedit ipsam itaque magnam mollitia nihil quam quibusdam repellendus, reprehenderit totam vel. Beatae, eum.", false),
];
}
ngOnInit() {
}
}
任务.html:
<app-task-item
*ngFor="let task of tasks | complete:SearchCompletePipe ; let index=index"
[task]="task"
>Loading . . .</app-task-item>
任务项目:
import { Component, OnInit, Input } from '@angular/core';
import { Task } from '../task';
@Component({
selector: 'app-task-item',
templateUrl: './task-item.component.html',
styleUrls: ['./task-item.component.css']
})
export class TaskItemComponent implements OnInit {
@Input() task: Task;
constructor() { }
ngOnInit() {
}
}
任务.html:
<td class="col-lg-1">{{task.id}}</td>
<td class="col-lg-2">{{task.name}}</td>
<td class="col-lg-6">{{task.description}}</td>
<td class="col-lg-3">
<div class="btn-group" role="group" aria-label="...">
<button type="button" class="btn btn-xs btn-info">edit</button>
<button type="button" class="btn btn-xs btn-danger">delete</button>
<button type="button" class="btn btn-xs btn-success">done</button>
</div>
</td>