[Angular 2] Passing Template Input Values to Reducers
Angular 2 allows you to pass values from inputs simply by referencing them in the template and passing them into your Subject.next() call. This lesson shows you how to make a number input and pass the value so you can configure how much you want the clock to change.
/**
* Created by wanzhen on 26.4.2016.
*/
import {Component} from 'angular2/core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/operator/map';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/startWith';
import 'rxjs/add/operator/scan';
import 'rxjs/add/operator/mapTo';
import {Subject} from "rxjs/Subject";
import {Store} from '@ngrx/store';
import {SECOND, HOUR} from './reducer'; @Component({
selector: 'app',
template: `
<input #inputNum type="number" value="">
<button (click)="click$.next(inputNum.value)">Update</button>
<h1>{{clock | async | date:'yMMMMEEEEdjms'}}</h1>
`
})
export class App {
click$ = new Subject()
.map( (number) => ({type: HOUR, payload: parseInt(number)})); seconds$ = Observable.interval()
.mapTo({type: SECOND, payload: }); clock; constructor(store:Store) {
this.clock = store.select('clock'); Observable.merge(
this.click$,
this.seconds$
)
.subscribe((action)=>{
store.dispatch(action)
})
}
}
[Angular 2] Passing Template Input Values to Reducers的更多相关文章
- [Angular 2] Passing Observables into Components with Async Pipe
The components inside of your container components can easily accept Observables. You simply define ...
- MyBatis(3.2.3) - Passing multiple input parameters
MyBatis's mapped statements have the parameterType attribute to specify the type of input parameter. ...
- [Angular 2] Passing data to components with @Input
@Input allows you to pass data into your controller and templates through html and defining custom p ...
- [Angular] Test component template
Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...
- [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] Passing data to components with 'properties'
Besides @Input(), we can also use properties on the @Component, to pass the data. import {Component, ...
- [Angular 2] Mapping Streams to Values to Affect State
While you have multiple streams flowing into your scan operator, you'll need to map each stream to t ...
- 解决angular ui-grid 中添加input date修改日期
需求:在angular ui-grid列表中添加一个日期组件来修改时间. 在angular ui-grid添加了一个html5 date input,后端返回的数据是YYYY-MM-DD,比如:201 ...
- angular学习笔记(四)- input元素的ng-model属性
input元素的ng-model属性: 用于将input的值和变量的值进行双向绑定 <!DOCTYPE html> <html ng-app> <head> < ...
随机推荐
- Character Encoding tomcat.
default character encoding of the request or response body: If a character encoding is not specified ...
- php小知识点
1.字符串可以里面的字符可以像数组一样访问,比如$s = "123";$s[1]就等于2,如果字符串为中文则会乱码,需要使用mb_substr进行截取: 2.php中的单引号(' ...
- HTML cellpadding与cellspacing属性
单元格(cell) -- 表格的内容 单元格边距(表格填充)(cellpadding) -- 代表单元格外面的一个距离,用于隔开单元格与单元格空间 单元格间距(表格间距)(cellspacing) - ...
- jquery获取元素方式
1 从集合中通过指定的序号获取元素 html: <div> <p>0</p> <p>1</p> <p>2</p> & ...
- js 联系电话验证实现
var str=$('#tele').val(); var regPartton=/1[3-8]+\d{9}/; ...
- 大脑皮层是如何工作的 《人工智能的未来》(<On intelligence>)读书笔记
PS:今年寒假的读书笔记,挖下的坑已无力再填...不过有关智能和人工智能的书还是要继续读的~ 正文: 我觉得书名翻译不是很确切,全书讨论的核心应该更是在“真”智能:讨论对人脑智能的理解,可以怎样帮助我 ...
- insert 和 if x is not None
insert(位置,元素) #!/usr/bin/python aList = [123, 'xyz', 'zara', 'abc'] aList.insert( 3, 2009) print &qu ...
- SVN管理工具Cornerstone之:创建分支、提交合并
创建工程的分支: 步骤: 1.选择左下角仓库repositories中的工程名->选择trunk->点击Branch->在提示框里填写分支名称create, 2.在做上角work ...
- MySQL重置root密码的几种方法(windows+Linux)
重置root密码的方法: windows系统下:1.停止mysql服务:2.新建文件init-root.txt,写上如下内容: update mysql.user set password = pas ...
- 在安装包运行时指定Component的安装路径
Basic MSI工程类型中如果实现动态指定安装路径的功能,下面介绍的方法也适用于InstallScript MSI工程. 1. 在Setup Design中找到相对应的Component. 2. 点 ...