[Angular 2] Using Pipes to Filter Data
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的更多相关文章
- 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 ...
- php://input,php://filter,data URI schema的那些事
一.php://input一句话木马 在调研dedecms的历史漏洞时,发现了dedecms安装文件曾经出过被植入后门的漏洞(SSV-ID站点include目录下shopcar.class.php文件 ...
- [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 ...
- angular学习(六)-- Filter
2.6 过滤器:Filter 内置过滤器 currency number date json uppercase lowercase orderBy limitTo filter 自定义过滤器
- [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 ...
- magento 自定义url路径 和 filter data 小结
背景是往一个第三方的搜索插件里面加入filter功能. 首先是路径,插件自己定义了一个router,类似于cms.那首先说说router好了,从入口一路追查的话,会发现最后进入的是Mage_Core_ ...
- Angular - - filter 过滤器
Filter Ng里的过滤器. currency:把一个数字格式化成货币模式(如$1,234.56).当没有提供任何货币符号时,默认使用当前区域的符号. 使用: HTML:{{ currency_ex ...
- angular的filter
angular的filter filter两种用法 1.在模板中使用filter {{expression|filter}}//基本用法 {{expression|filter1|filter2|fi ...
- 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 ...
随机推荐
- thinksns消息提示的实现机制(转)
转自:http://jingyan.baidu.com/article/f25ef2541718eb482c1b8215.html thinksns的消息提示不是实时的,而是1分钟向服务器请求一次,再 ...
- CentOS 6.5 IP 设置
DEVICE=eth0TYPE=EthernetUUID=7d6d54e0-054d-472b-8cc1-080f16ef36c1ONBOOT=yesNM_CONTROLLED=yesBOOTPROT ...
- 本大神教你用PHP把文本内容转换成16进制数字,进行加密
<?php $a="杨波"; $b = bin2hex($a); echo $a."<br />"; $c = pack("H*&q ...
- html5 实现手机端相册浏览功能
原文地址:http://www.cootm.com/?p=710 在网上找到个浏览图片的jq插件,针对手机做的非常不错,看到乐享的微信微站新开发的功能就是这个,特此分享下! 时间匆忙,没做代码分析,勿 ...
- YII 小部件 解决多选按钮和单选按钮不在同一水平上 'separator'=>' '
主要是添加separator属性(这里)$hoddy,$sex在控制器里面定义的数组,然后render传过来的 <td> <?php echo $form-> ...
- vim技巧:折叠快捷键
vim技巧:折叠快捷键 以前用的挺熟的,一段时间不用了,快捷键又忘了,不得不重新再看手册,今天专门整理一下,以后查找起来也比较方便. zc 折叠,只折叠最外层的折叠zC 对所在范围内所有嵌套的折叠点进 ...
- 【技术贴】同一台机器Tomcat7多版本共存配置文档
首先准备好自己下载的Tomcat7的绿色版,一定要是解压的绿色版不能使exe安装包.因为exe安装版很多变量不好配置,我以前最喜欢exe版了,方便快捷,但是我发现还是绿色解压版比较好,优化配置等也很好 ...
- libevent带负载均衡的多线程使用示例
功能: 主线程根据负载工作线程负载均衡算法,每隔一秒钟向特定的工作线程发送一条字符串信息,工作线程简单的把字符串信息打开出来. Makefile eventtest : eventtest.c ...
- 给java中的System.getProperty添加新的key value对
由于系统被格了,所以,现在的java项目配置不对,代码里面的配置类调用了一个System.getProperty("env")发现找不到该变量的值,以前一直能找到的. 其实就是以前 ...
- mangos搭建
github地址:https://github.com/mangos/MaNGOS MaNGOS 是( Massive Network Game Object Server) 的缩写.由于暴雪公司对类 ...