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. windows7 jdk 环境变量添加

    JAVA_HOME D:\Java;PATH %JAVA_HOME%\bin;%JAVA_HOME%\jre\bin;CLASSPATH .;%JAVA_HOME%\lib;%JAVA_HOME%\l ...

  2. 一句实现jquery导航栏

    /*mine 才疏学浅,望大神绕行 */ .current{ color: red; font-size: large; } $(function(){ //实现点击标题的css和.lev1下面的a标 ...

  3. Bootstrap_表单_表单控件

    一.输入框input 单行输入框,常见的文本输入框,也就是input的type属性值为text. 在Bootstrap中使用input时也必须添加type类型,如果没有指定type类型,将无法得到正确 ...

  4. 深入Java虚拟机读书笔记第五章Java虚拟机

    Java虚拟机 Java虚拟机之所以被称之为是虚拟的,就是因为它仅仅是由一个规范来定义的抽象计算机.因此,要运行某个Java程序,首先需要一个符合该规范的具体实现. Java虚拟机的生命周期 一个运行 ...

  5. JQUERY 键盘事件

    一 一.首先需要知道的是: 1.keydown()keydown 事件会在键盘按下时触发. 2.keypress()keypress 事件会在敲击按键时触发,我们可以理解为按下并抬起同一个按键. 3. ...

  6. xgboost中如何自定义metric(python中)

    正好在参加携程的比赛,用的xgboost的算法,但携程比赛的测评函数比较奇怪,不是传统的那些,而是取precision≥0.97的情况下,recall的最大值.那无疑这个测评函数是要自己写的(官方没给 ...

  7. C语言学习之笔记

    第一章 概述 1. C语言的特点 ①语言简洁.紧凑,使用方便.灵活.共有32个关键字(也称保留字),9种控制语句. ②运算符丰富,共有34种运算符. ③数据结构丰富,数据类型有:整型.实型.字符型.数 ...

  8. [转载]网络编辑必知常识:什么是PV、UV和PR值 zz

    1.什么是pv PV(page view),即页面浏览量,或点击量;通常是衡量一个网络新闻频道或网站甚至一条网络新闻的主要指标. 高手对pv的解释是,一个访问者在24小时(0点到24点)内到底看了你网 ...

  9. Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四)

    Solr4.8.0源码分析(23)之SolrCloud的Recovery策略(四) 题记:本来计划的SolrCloud的Recovery策略的文章是3篇的,但是没想到Recovery的内容蛮多的,前面 ...

  10. 【译】UI设计基础(UI Design Basics)--自动适配与布局(Adaptivity and Layout)(四)

    2.3  自动适配与布局(Adaptivity and Layout) 2.3.1  开发成自动适配(Build In Adaptivity) 用户通常希望在自己的所有设备,各种场景中使用他们喜欢的a ...