[Angular 2] Pipes with Multiple Parameters
2015-11-01 17:33
337 查看
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) )); } }
相关文章推荐
- AngularJS 中的Promise --- $q服务详解
- AngularJS教程
- [Angular 2] Create a simple search Pipe
- [Angular 2] Pipe Purity
- angularjs惯性滚动指令
- [angularjs之我见] AngularJs 的DI实现
- 跨域解决方案 & 使用angularJS和jQuery进行Ajax请求的差异
- angularjs自定义折线图+滑动条指令
- AngularJS $watch的用法
- requirejs+angularjs搭建SPA页面应用
- AngularJS入门
- AngularJS 指令(Directivce )一
- AngularJs angular.forEach、angular.extend
- AngularJS内置指令
- angularjs依赖服务注入写法的注意点
- angularjs 绑定enter事件的两种方法
- AngularJS中如何绑定html内容
- AngularJS: 'Template for directive must have exactly one root element' when using 'th' tag in directive template
- angularJs-HelloWorld
- angular 版本区间