[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 ...
随机推荐
- deb文件安装命令
一般在此类发行版中可以直接双击安装 手动安装.如果您喜欢使用终端,您需要管理员权限来安装一个 .deb 文件. 打开终端后,输入: sudo dpkg -i package_file.deb 要卸载一 ...
- 关于js闭包杂记
闭包:一个函数oneF里return了另一个函数innerF,然后在oneF外面运行了函数innerF,如果innerF里有用到在oneF里定义的变量,则此时依然可以引用到, 但是变量值不是定义函数i ...
- C++ primer学习方法
C++ primer学习: 第一次可以跳着看.关键是要尽快用起来,在使用中熟练,而不是在细节中迷失. 以C++ Primer第五版为例,第一遍读的时候: Part1也就是前七章,除了6.6,6 ...
- css、js的相互阻塞
先决条件:脚本前面存在外部样式 以下试验虽然是在chrome下,但是对于IE8+以及其他浏览器也适用. 1.内联脚本(http://jsbin.com/mudab/1) <!DOCTYPE ht ...
- 转:Yelp开发团队发布内部网站设计指南
原文来自于:http://www.infoq.com/cn/news/2014/02/yelp-style-guide 近日,Yelp开发团队在博客发布消息:Yelp公开了内部网站设计指南.这份文档此 ...
- android上传图片至服务器
本实例实现了android上传手机图片至服务器,服务器进行保存 服务器servlet代码publicvoid doPost(HttpServletRequest request, HttpServle ...
- Entity Framework with MySQL 学习笔记一(乐观并发)
在做项目时,通常我们对乐观并发有几种处理模式 1. 告诉用户此数据已被其他人捷足先登,更改了.你就算新一下重来吧. 2.直接把数据覆盖上去,我最大. 3.用被人的数据. 这里给出 code first ...
- ELK( ElasticSearch+ Logstash+ Kibana)分布式日志系统部署文档
开始在公司实施的小应用,慢慢完善之~~~~~~~~文档制作 了好作运维同事之间的前期普及.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 软件下载地址: https://www.e ...
- 当DOCKER遇上ESXI
特别是你要为DOCKER窗口设置静态IP,且和公司局域网打成一片的时候, 苦逼的测试就会开始,我差不多前前后后测试了四五天,一百多个容器报废. NETNS,NSENTER,PIPWORK,各种镜像合下 ...
- Cracking the coding interview--Q1.7
原文 Write an algorithm such that if an element in an MxN matrix is 0, its entire row and column are s ...