[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 ...
随机推荐
- 《du命令》-linux命令五分钟系列之三
本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...
- 利用正则表达式,给Json字段加引号
{ scheme: [ { query: [ [{ id: 'stdNumber', title: "标准号", compareType: 2 }], [{ id: 'CnName ...
- PHP下编码转换函数mb_convert_encoding与iconv的使用说明
mb_convert_encoding这个函数是用来转换编码的. 不过英文一般不会存在编码问题,只有中文数据才会有这个问题.比如你用Zend Studio或Editplus写程序时,用的是gbk编码, ...
- DedeCMS时间格式
时间格式 {dede:field name='pubdate' function='strftime("%Y年%m月%d日 %H:%M:%S","@me")' ...
- 史上最强NDK入门项目实战
目标: 利用NDK生成SO库,使用SO库进行JNI调用,在Android sdcard创建文件并写入数据. 工具: NDK1.5 R1, android SDK1.5 R1, SDCARD, Ecli ...
- PHP常用函数和常量
PHP常用系统常量 __FILE__ 文件的完整路径和文件名.如果用在被包含文件中,则返回被包含的文件名.自 PHP 4.0.2 起,总是包含一个绝对路径(如果是符号连接,则是解析后的绝对路径),而在 ...
- Shell 控制并发
方法1: #!/bin/bash c=0 for i in `seq -w 18 31`;do while [ $c -ge 3 ];do c=$(jobs -p |wc -w) sleep 1s d ...
- Android RecyclerView Adapter 新式用法之SortedListAdapterCallback
引言 前几天在同事的提醒下发现V7中有了一个新的工具类SortedListAdapterCallback,配合RecyclerView Adapter和SortedList一起使用更加方便的管理我们在 ...
- 常用Firefox扩展
最近思维混乱,无心做事,故整理下东西.(PS:有些是firefox自带的.) 1.标签页管理器 2.1.41 用途:在新标签页打开书签.历史.地址.搜索. 主页:http://www.firefox. ...
- ipconfig的C语言实现
首先,这篇文章实现了两种方法查询IP,实现截图如下: 第一种方法时调用系统命令,代码如下: #include <cstdlib> #include <iostream> usi ...