[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 ...
随机推荐
- xubuntu14.04截图,彻底到Linux一个半月后记
前言 自学计算机技术,越到后面,越依赖ubuntu,以致于很多时候都是一开机就打开虚拟机上的ubuntu10.04,Linux已经变得越来越重要了. 2014-04-17,ubuntu14.0 ...
- php实现的太平洋时间和北京时间互转的自定义函数
date_default_timezone_set('Asia/Shanghai'); $time = time(); } date_default_timezone_set('Pacific/Api ...
- SQL 测试
1.SQL 指的是? 您的回答:Structured Query Language 2.哪个 SQL 语句用于从数据库中提取数据? 您的回答:SELECT 3.哪条 SQL 语句用于更新数据库中的数据 ...
- SQL Server 连接字符串和身份验证
SQL Server .NET Data Provider 连接字符串包含一个由一些属性名/值对组成的集合.每一个属性/值对都由分号隔开. PropertyName1=Value1;P ...
- Python自动化运维之26、Web框架本质、MVC与MTV
一.Web框架本质 众所周知,对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. #!/usr/bin/env python #coding:ut ...
- 那些年被我坑过的Python——玄而又玄(第六章 面向对象编程基础)
面向对象编程: 面向对象顾名思义,就是把组织代码的粒度从函数级别抽象到对象级别,对象是通过类来生成的,类可以想象为模板或进本框架而对象是在原有模板或框架的基础上增加详细信息的实体,类,有分类.聚类的含 ...
- 使用windows live writer 编辑博客日志
使用Windows Live Writer 编辑日志 一 意义 写博客日志是个需要坚持的好习惯.使用Windows Live Writer,能不受网页自带编辑器限制. Markdown支持.安装mar ...
- cloudera目录位置
http://www.aboutyun.com/thread-9189-1-1.html 这里来的嘿嘿. 1. 相关目录/var/log/cloudera-scm-installer : 安装日志目录 ...
- iscc2016-basic-find-to-me
额 第一题就暴力搜索了 已知仿射加密变换为c=(11m+8)mod26,试对密文sjoyuxzr解密 #include <stdio.h> int main(void) { int m,c ...
- MFC 如何改变对话框按钮上的文字
原文地址:http://blog.163.com/wenxianliang08@126/blog/static/8358326320110300643282/ 什么是标记菜单 如何标记菜单 如何 ...