码迷,mamicode.com
首页 > 其他好文 > 详细

[Angular 2] Pipes with Multiple Parameters

时间:2015-11-01 17:51:19      阅读:331      评论:0      收藏:0      [点我收藏+]

标签:

Showing how to set up a Pipe that takes multiple updating inputs for multiple Component sources.

import {Component, View, NgFor, FORM_DIRECTIVES} from ‘angular2/angular2‘;
import {TodoService} from ‘./todoService‘;
import {TodoItemRender} from ‘./todoItemRender‘;
import {StartsWith} from ‘./startsWith‘;
import {SimpleSearch} from ‘./simpleSearch‘;
import {LetterSelect} from ‘./letterSelect‘;
import {TodoSearch} from ‘./todoSearch‘;

@Component({
    selector: ‘todo-list‘
})
@View({
    pipes: [StartsWith, SimpleSearch],
    directives: [NgFor, TodoItemRender, FORM_DIRECTIVES, LetterSelect, TodoSearch],
    template: `
          <div>
                <todo-search #todo-search></todo-search>
                {{todoSearch.term}}
                <todo-item-render
                    *ng-for="#todo of todoService.todos
                    | simpleSearch: [‘title‘,‘action‘] : todoSearch.term"
                    [todoinput]="todo"
                >
                </todo-item-render>
          </div>
    `
})

export class TodoList{
    constructor(
        public todoService:TodoService
    ){

    }
}

 

import {Pipe} from ‘angular2/angular2‘;

@Pipe({
    name: ‘simpleSearch‘,
    pure: false
})

export class SimpleSearch{

    transform(value, [fields, letter]:[string[], string]){

        return value.filter((item)=>
            fields.some((field)=>
                item[field].includes(letter)
            ));
    }
}

 

[Angular 2] Pipes with Multiple Parameters

标签:

原文地址:http://www.cnblogs.com/Answer1215/p/4928253.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!