[Angular 2] Build a select dropdown with *ngFor in Angular 2
We want the start-pipe more flexable to get param, so when using it, we pass a second param as 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">
------------------------------
[Angular 2] Build a select dropdown with *ngFor in Angular 2的更多相关文章
- JSF 2 multiple select dropdown box example
In JSF, <h:selectManyMenu /> tag is used to render a multiple select dropdown box – HTML selec ...
- Angular 1 深度解析:脏数据检查与 angular 性能优化
TL;DR 脏检查是一种模型到视图的数据映射机制,由 $apply 或 $digest 触发. 脏检查的范围是整个页面,不受区域或组件划分影响 使用尽量简单的绑定表达式提升脏检查执行速度 尽量减少页面 ...
- [Angular CLI] Build application without remove dist folder for Docker Volume
When we develop the Angular app inside Docker container, we can simulate Production envioment by bui ...
- angular ng build --prod 打包报错解决方案
使用以下代码 就不报错了 ng build --prod --no-extract-license 打包命令 使用以下代码 就不报错了 ng build --prod --no-extrac ...
- Angular中 build的时候遇到的错误--There are multiple modules with names that only differ in casing
今天早上遇到一个Angular的编译的时候的错误 具体信息: There are multiple modules with names that only differ in casing.This ...
- Angular 学习笔记 (Material Select and AutoComplete)
记入一些思考 : 这 2 个组件有点像,经常会搞混. select 的定位是选择. 目前 select 最糟糕的一点是 not search friendly. 还有当需要 multiple sele ...
- webstorm 打包angular Module build failed: Error: No PostCSS Config found
angular创建项目后,在webstorm中启动时,报出如题错误,奇怪的是我从命令行启动(ng server)是没有问题的,多方寻求无果,在网上看到过说要加一个配置文件,我不信.我觉得是我配置哪里有 ...
- angular中的 input select 值绑定无效,以及多出一个空白选项问题
问题: <!-- 问题标签 --> <select ng-model="sortType"> <option value="1"& ...
- Angular JS ng-model对<select>标签无效的情况
使用场景一: <select ng-if="item.award_type==1" id="award{{$index+1}}" name="X ...
随机推荐
- 推荐一个CMMI认证查询网站
随着软件企业的增多和意识的增强,越来越多公司开始做CMMI的认证评估,由于国内网速和CMMI官网的网站综合原因,打开速度超级慢. 所以本文推荐一个CMMI认证查询网站,认证后的结果查询可以点这里查询: ...
- form表单提交
1.form表单提交.html页面失败 <%--客户端form--%> <form id="form2" action="LoginOne.html&q ...
- php 设置报错等级
定义和用法: error_reporting() 设置 PHP 的报错级别并返回当前级别. 函数语法: error_reporting(report_level) 如果参数 level 未 ...
- Ehcache入门(一)——开发环境的搭建
EhCache 是一个纯Java的进程内缓存框架,具有快速.精干等特点,是Hibernate中默认的CacheProvider. 那么.如何搭建Ehcache的开发环境呢? 1.下载相关的jar包,这 ...
- C++拾遗(五)语句相关
前缀格式与后缀格式 对于表达式:后缀如 i++ 表达式的值仍是 i,在遇到下一个顺序点后再将 i 加1.前缀 ++i 表达式的值就是(i+1),先计算表达式的值,不需要等待 顺序点. 对于类:前缀函数 ...
- [转]Windows中的句柄(handle)
1.句柄是什么? 在windows中,句柄是和对象一一对应的32位无符号整数值.对象可以映射到唯一的句柄,句柄也可以映射到唯一的对象.2.为什么我们需要句柄? 更准确地说,是windows需要 ...
- nodejs学习记录
一.环境搭建 1.安装express 局部安装 npm i express 全局安装 npm i -g express (命令行express无法使用) 环境变量 npm i -g express-g ...
- ubuntu 下telnet 操纵memcache 实现
memcache作为一款优秀的进程外缓存,常常被运用于高并发系统架构中.这里主要谈谈怎么通过telnet工具,查看memcache运行状况并对其key进行管理维护.假设memcache安装目录:/us ...
- JBPM4.4GPD设计器中文乱码问题的另一种解决方法
在eclipse中使用JBPM4.4的设计器时,输入中文后直接查看Source发现xml里中文全都乱码了,这时候大约整个人都不好了!赶紧百度.谷歌,搜到的多数结果都是要你在eclipse.ini或my ...
- Linux_cloudera-scm-agent: unrecognized service