【发布时间】:2016-05-11 19:59:49
【问题描述】:
我在 egghead.com 上关注 John Lindquist 关于 Angular 2 的教程,在做了与他完全相同的事情之后,我没有得到相同的结果。
关于课程 17。
我有一个完美的自定义过滤器:
started-pipe.ts
import {Pipe} from '@angular/core';
@Pipe({
name: "started"
})
export class StartedPipe{
transform(value, [status]){
return value.filter((item)=> item.status === "started");
}
}
待办事项列表.ts
import {Component, Input} from '@angular/core';
import {TodoService} from "./todo-service";
import {TodoItemRenderer} from "./todo-item-renderer";
import {StartedPipe} from './started-pipe';
@Component({
selector: 'todo-list',
pipes: [StartedPipe],
directives: [TodoItemRenderer],
template: `
<div>
<ul>
<li *ngFor="let todo of todoService.todos | started : 'started'">
<todo-item-renderer
[todo]="todo"
(toggle)="todoService.toggleTodo($event)">
</todo-item-renderer>
</li>
</ul>
</div>
`
})
export class TodoList{
@Input() status;
constructor(public todoService: TodoService){}
}
但是当我想使用我的转换值的数组 arg 时,它不再起作用了:
started-pipe.ts
import {Pipe} from '@angular/core';
@Pipe({
name: "started"
})
export class StartedPipe{
transform(value, [status]){
return value.filter((item)=> item.status === status);
}
}
如果你有想法,欢迎!
谢谢。
【问题讨论】:
标签: angular