[Angular 2] Build a select dropdown with *ngFor in Angular 2
2016-03-22 19:29
393 查看
We want the start-pipe more flexable to get param, so when using it, we pass a second param as status:
It will be handled as a second param which is an array of the transform() function:
So No we will only pipe 'started' status. We need a selector to handle the status:
And pass the output to the list:
Then in the list, we use that selected status:
------------------------------
<li *ngFor="#todo of todoService.todos | started : 'started'">
It will be handled as a second param which is an array of the transform() function:
transform(todos, [status]){ return todos.filter( (todoModel) => { // Only showing the todo starts with 'e' return todoModel.status === status; } ) }
So No we will only pipe 'started' status. We need a selector to handle the status:
import {Component, EventEmitter, Output} from 'angular2/core'; @Component({ selector: "status-selector", template: ` <div> <select #sel (change)="selectedStatus.emit(sel.value)"> <option *ngFor="#status of statuses"> {{status}} </option> </select> </div> ` }) export class StatusSelector{ @Output() selectedStatus = new EventEmitter(); statuses = ["started", "completed"]; ngOnInit(){ this.selectedStatus.emit(this.statuses[0]); } }
And pass the output to the list:
template: ` <todo-input></todo-input> <status-selector (selectedStatus)="status=$event"></status-selector> <todo-list [status]="status"></todo-list> `
Then in the list, we use that selected status:
<li *ngFor="#todo of todoService.todos | started : status">
------------------------------
相关文章推荐
- QuerySyntaxException: unexpected token: user_id near line 1, column 29 [from model.Demand d where d
- iOS开发之UITextView,设置textView的行间距及placeholder
- PKIX path building failed
- UESTC 1012 Ladygod (多校联盟3)
- UIButton - 设置图片及文字、文字左对齐
- easyui.min.js 报错rows is undefined
- java中的goto,const,ttrue,false,null
- 【优先队列】HDU1509Windows Message Queue
- java中queue的使用
- iOS开发—UILable详解
- UESTC 1271 Search gold (DP,多校联盟3)
- 【转】Android UI开发第三十一篇——Android的Holo Theme
- android SpannableStringBuilder
- GUID(全局唯一标识符)
- IT十八掌作业_java基础第十六天_GUI/socket
- .NET跨平台之Sake和KoreBuild
- ios8 UITableView设置 setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- 探究requestDisallowInterceptTouchEvent失效的原因
- A - Farey Sequence——(筛法求欧拉函数)
- 【转】Android UI开发第二十四篇——Action Bar