Pipes allow you to change data inside of templates without having to worry about changing it in the Controller. Creating a custom Pipe is as simple as giving it a name and a transform function that output what you expect.

startsWith.ts:

import {Pipe} from 'angular2/angular2';

@Pipe({
name: 'startsWith'
}) export class StartsWith{ transform(value, [field, letter]){ // 1: value passed in, 2: array
return value.filter((item) => {
return item[field].startsWith(letter);
})
}
}

todoList:

/**
* Created by wanzhen on 23.10.2015.
*/
import {Component, View, NgFor} from 'angular2/angular2';
import {TodoService} from './todoService';
import {TodoItemRender} from './todoItemRender';
import {StartsWith} from './startsWith'; @Component({
selector: 'todo-list'
})
@View({
pipes: [StartsWith],
directives: [NgFor, TodoItemRender],
template: `
<div>
<todo-item-render
*ng-for="#todo of todoService.todos | startsWith:'title':'e'" // title is the prop of #todo, filter get only start letter with 'e'
[todoinput]="todo"
>
</todo-item-render>
</div>
`
}) export class TodoList{
constructor(
public todoService:TodoService
){ }
}

[Angular 2] Using Pipes to Filter Data的更多相关文章

  1. kibi - join and filter data from multiple Elasticsearch indexes

    Kibi extends Kibana 4.6.4 with data intelligence features. The core feature of Kibi is the capabilit ...

  2. php://input,php://filter,data URI schema的那些事

    一.php://input一句话木马 在调研dedecms的历史漏洞时,发现了dedecms安装文件曾经出过被植入后门的漏洞(SSV-ID站点include目录下shopcar.class.php文件 ...

  3. [Postgres] Filter Data in a Postgres Table with Query Statements

    We have all this data, but how do we answer questions about it? In this lesson we’ll learn how to fi ...

  4. angular学习(六)-- Filter

    2.6 过滤器:Filter 内置过滤器 currency number date json uppercase lowercase orderBy limitTo filter 自定义过滤器

  5. [GraphQL] Filter Data Based on Query Arguments with GraphQL

    With GraphQL, every field and nested object can have a set of arguments which can be used to request ...

  6. magento 自定义url路径 和 filter data 小结

    背景是往一个第三方的搜索插件里面加入filter功能. 首先是路径,插件自己定义了一个router,类似于cms.那首先说说router好了,从入口一路追查的话,会发现最后进入的是Mage_Core_ ...

  7. Angular - - filter 过滤器

    Filter Ng里的过滤器. currency:把一个数字格式化成货币模式(如$1,234.56).当没有提供任何货币符号时,默认使用当前区域的符号. 使用: HTML:{{ currency_ex ...

  8. angular的filter

    angular的filter filter两种用法 1.在模板中使用filter {{expression|filter}}//基本用法 {{expression|filter1|filter2|fi ...

  9. Jasper_filter data_pass field data from main to sub to filter some data

    main report: 1 add variable <variable name="Variable_rule" class="java.lang.String ...

随机推荐

  1. jquery获取元素的所有宽高(包括内边距和外边距)

    width() - 返回元素的宽度.height() - 返回元素的高度.innerWidth() 方法返回元素的宽度(包括内边距).                    innerHeight() ...

  2. loadView与viewDidLoad不同 && loadView学习总结

    loadView学习总结 UIViewController类或其子类会在初始化时创建一个UIView对象,会作为控制器的默认视图显示出来,可以通过self.view寻址访问.但没有调用loadView ...

  3. eclipse 比较好的插件

    tomcat 插件 egit github 插件 subeclipse 插件 Properties Editor Properties Editor 编辑java的属性文件,并可以自动存盘为Unico ...

  4. 批处理WMIC查看补丁情况

    最近补丁比较多,需要看系统打了些啥,哪些没打的BAT: wmic qfe GET hotfixid > a.txt&(for %i in (KB3076321 KB3072604 KB3 ...

  5. "sessionFactory " or "hibernateTemplate " is required异常

    <beans    xmlns="http://www.springframework.org/schema/beans"    xmlns:xsi="http:/ ...

  6. 获取Delphi所有类的类信息

    Delphi遍历进程中所有Class的TypeInfo,即便是在implementation中的class或者其他 class的private的子class. 一般普通EXE中的TypeInfo存放在 ...

  7. 中文简体windows CMD显示中文乱码解决方案

    因为重装系统,以前是英文的,现在的镜像文件是中文简体windows 10.所以只能将就使用. 下载了JDK,CMD 写了命令java,结果一堆乱码(问号???).发现System的locale默认设置 ...

  8. linux下so动态库一些不为人知的秘密(转)

    linux 下有动态库和静态库,动态库以.so为扩展名,静态库以.a为扩展名.二者都使用广泛.本文主要讲动态库方面知识.基本上每一个linux 程序都至少会有一个动态库,查看某个程序使用了那些动态库, ...

  9. qml学习:对象和属性

    qml学习:对象和属性 本文博客链接:http://blog.csdn.net/jdh99,作者:jdh,转载请注明. 参考文档<<Qt及Qt Quick开发实战精解.pdf>> ...

  10. 【HDOJ】3329 The Flood

    超简单BFS. /* 3329 */ #include <iostream> #include <queue> #include <cstdio> #include ...