[Angular 2] Create a simple search Pipe
This lesson shows you how to create a component and pass its properties as it updates into a Pipe to make a simple searchable list.
import {Pipe} from 'angular2/angular2';
@Pipe({
name: 'simpleSearch'
})
export class SimpleSearch{
transform(value, [field, letter]){
return value.filter((item) => {
return item[field].includes(letter);
})
}
}
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
| startsWith:'title':letterSelect.selectedLetter)
| simpleSearch:'title':todoSearch.term"
[todoinput]="todo"
>
</todo-item-render>
<letter-select #letter-select></letter-select>
</div>
`
})
export class TodoList{
constructor(
public todoService:TodoService
){
}
}
You can group something together by using (), so todoService.todos will piped by startWith, and its result will be handled by simpleSearch.
[Angular 2] Create a simple search Pipe的更多相关文章
- [Angular 2] Filter items with a custom search Pipe in Angular 2
This lessons implements the Search Pipe with a new SearchBox component so you can search through eac ...
- [CareerCup] 4.3 Create Minimal Binary Search Tree 创建最小二叉搜索树
4.3 Given a sorted (increasing order) array with unique integer elements, write an algorithm to crea ...
- Create a simple REST web service with Python--转载
今日尝试用python建立一个restful服务. 原文地址:http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-r ...
- [Angular] Create a simple *ngFor
In this post, we are going to create our own structure directive *ngFor. What it should looks like i ...
- [Angular] Using directive to create a simple Credit card validator
We will use 'HostListener' and 'HostBinding' to accomplish the task. The HTML: <label> Credit ...
- [Angular 2] Create template with Params
Angular 2 templates have a special let syntax that allows you to define and pass a context when they ...
- [Angular 2] Create Shareable Angular 2 Components
Components that you use across multiple applications need to follow a module pattern that keeps them ...
- [Angular 2] Create Angular 2 Porject with Angular CLI
Install: npm i -g angular-cli Create a project: ng new hello-angular2 Run the project: cd hello-angu ...
- CHtmlEditCtrl(1) : Use CHtmlEditCtrl to Create a Simple HTML Editor
I needed a lightweight HTML editor to generate "rich text" emails, so I decided to explore ...
随机推荐
- 【转】 C语言自增自减运算符深入剖析
转自:http://bbs.csdn.net/topics/330189207 C语言的自增++,自减--运算符对于初学者来说一直都是个难题,甚至很多老手也会产生困惑,最近我在网上看到一个问题:#in ...
- 【转】ThinkPHP中数据库操作返回值总结
Thinkphp中的Think\Model类提供了数据库的基本CURD(Create.Update.Read及Delete),通过该类可以很便捷的进行操作.Model类及扩展类主要的方法有: Crea ...
- python中文字符串前加u
我明明在编码前就加上了# -*- coding: UTF-8 -*-可是运行时还是出错了, # -*- coding: UTF-8 -*- 这句是告诉python程序中的文本是utf-8编码,让pyt ...
- 嵌套JSON 取出name与value
好久不用都忘了 mark下 $.each( { name: "John", lang: "JS" }, function(i, n){ alert( &qu ...
- Left Mouse Button
FZU:http://acm.fzu.edu.cn/problem.php?pid=1920 题意:叫你玩扫雷游戏,已经告诉你地雷的位置了,问你最少点几次鼠标左键可以赢这盘扫雷 题解:直接DFS,(注 ...
- siem主流厂商
http://www.scmagazine.com/siem/products/6428/5/ http://www.edu.cn/wlaq_6572/20131217/t20131217_10532 ...
- c# 类;一维数组;二维数组
1. 输入邮箱帐号,判断格式是否正确 (1)有且只有一个@ Contains IndexOf ==LastIndexOf (2)不能以@开头 StartsWi ...
- 数学(快速数论变换):SDOI2015 序列统计
[题目描述] 小C有一个集合S,里面的元素都是小于M的非负整数.他用程序编写了一个数列生成器,可以生成一个长度为N的数列,数列中的每个数都属于集合S. 小C用这个生成器生成了许多这样的数列.但是小C有 ...
- VS2010如何生成release文件
点击生成-->配置管理器-->活动解决方案配置下拉菜单中选择release就行了,最后再编译一下就在相应的目录下生成了
- Delphi NativeXml读取中文乱码问题解决
NativeXml默认的字符类型为Utf8String,有时在读取中文时还是会出现乱码问题,在329版本中提供一种类型转换函数sdUtf8ToWide(),我们可以这样sdUtf8ToWide(AXm ...