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的更多相关文章

  1. [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 ...

  2. [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 ...

  3. Create a simple REST web service with Python--转载

    今日尝试用python建立一个restful服务. 原文地址:http://www.dreamsyssoft.com/python-scripting-tutorial/create-simple-r ...

  4. [Angular] Create a simple *ngFor

    In this post, we are going to create our own structure directive *ngFor. What it should looks like i ...

  5. [Angular] Using directive to create a simple Credit card validator

    We will use 'HostListener' and 'HostBinding' to accomplish the task. The HTML: <label> Credit ...

  6. [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 ...

  7. [Angular 2] Create Shareable Angular 2 Components

    Components that you use across multiple applications need to follow a module pattern that keeps them ...

  8. [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 ...

  9. 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 ...

随机推荐

  1. Poj 3667

    这是第一题线段树的区间合并的题: 这类的题用于求连续的最长长度什么的: 这题我看的是一篇比较不错的博客: 我把我的理解注释在代码里了: #include <iostream>#includ ...

  2. 解决Silverlight5_tools无法安装问题(试验已成功)

    当前位置: 银光首页 > Silverlight > Silverlight学习教程 > 命令:regedit 打开节点:HKEY_LOCAL_MACHINE\SOFTWARE\Mi ...

  3. MySql拾遗

    1.“1130-Host is not allowed to connect to this MySQL server” 满世界的人都告诉你,到user表中把root + localhost的“loc ...

  4. 自己动手实现智能指针auto_ptr

    面试的时候,我们经常会被问到如何自己动手实现智能指针auto_ptr.今天我就一边参考STL库中的源代码,一边将auto_ptr的实现敲一遍. auto_ptr归根到底是一个模版类,那么这个类要实现哪 ...

  5. Linux&shell 之基本Shell命令

    写在前面:案例.常用.归类.解释说明.(By Jim) 文件和目录列表lsls -F (用斜杠区分目录和文件)ls -a (把隐藏文件一并显示出来)ls -l (同ll,显示详细信息)ls -l 文件 ...

  6. hg 证书验证失败

    hg clone https://bitbucket.org/pygame/pygame 出现abort: error: _ssl.c:504: error:14090086:SSL routines ...

  7. 1B. Spreadsheets

    题目大意: 行和列的两种方式. A是1, B是2,....Z是26, AA是27, AB是28........... 如: BC23代表55列23行 还有一种表示方法:R23C55, 代表23行,55 ...

  8. 【转】BLE 学习记录

    原文网址:http://m.blog.csdn.net/blog/chiooo/43985401 BLE 学习记录 ANROID BLE 开发,基于 bluetoothlegatt 分析 mBluet ...

  9. form.Show()和form.ShowDialog()的区别、新建一个form和MessageBox.Show()的常见用法

    一:form.Show()和form.ShowDialog()的区别 a. 任何窗体(派生于基类Form的类),都可以以两种方式进行显示. //非模式窗体From qform=new Form();q ...

  10. IIS7授权错误:“无法验证对路径的访问”的解决方法

    解决方法: iis7 无法验证对路径的访问 1.打开IIS 7管理器,鼠标单击定位到出现了这个错误的网站. 2.在IIS 7管理器的右边,选择“基本设置”. 3.在弹出的“编辑网站”对话框中,单击“连 ...