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的更多相关文章

  1. [Angular 2] Passing Observables into Components with Async Pipe

    The components inside of your container components can easily accept Observables. You simply define ...

  2. MyBatis(3.2.3) - Passing multiple input parameters

    MyBatis's mapped statements have the parameterType attribute to specify the type of input parameter. ...

  3. [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 ...

  4. [Angular] Test component template

    Component: import { Component, Input, ChangeDetectionStrategy, EventEmitter, Output } from '@angular ...

  5. [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 ...

  6. [Angular 2] Passing data to components with 'properties'

    Besides @Input(), we can also use properties on the @Component, to pass the data. import {Component, ...

  7. [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 ...

  8. 解决angular ui-grid 中添加input date修改日期

    需求:在angular ui-grid列表中添加一个日期组件来修改时间. 在angular ui-grid添加了一个html5 date input,后端返回的数据是YYYY-MM-DD,比如:201 ...

  9. angular学习笔记(四)- input元素的ng-model属性

    input元素的ng-model属性: 用于将input的值和变量的值进行双向绑定 <!DOCTYPE html> <html ng-app> <head> < ...

随机推荐

  1. 什么是NSAssert?

    断言, 判断是否符合某个特定条件, 符合就继续运行程序, 反之就抛出异常, 后面为自定义错误提示, 也可以使用NSParameterAssert, 在调试上有着很大的方便 int a = 0; NSA ...

  2. entity framework 动态条件

    entity framework 动态条件 问题:在实际编码过程中,根据不同的选择情况,会需要按照不同的条件查询数据集 如:状态confirmStatus ,如果为空的时候,查询全部,如果有具体值的时 ...

  3. UVA 10285 - Longest Run on a Snowboard (记忆化搜索+dp)

    Longest Run on a Snowboard Input: standard input Output: standard output Time Limit: 5 seconds Memor ...

  4. 理解javascript之 对象

    大纲: 1.介绍attribute property的异同,翻译自http://javascript.info/tutorial/attributes-and-custom-properties#pr ...

  5. 可以让PHP编程事半功倍的类库

    在用php开发网站的时候,使用面向对象的方法确实可以提高代码复用率,减少代码冗余.而对初学者更友好的是,PHP开发网站所需要的大部分类库,网上都有十分优秀的类库存在了.作为一个程序猿当然不能重复制造轮 ...

  6. C++多重继承虚表的内存分布

    接前面虚表的内存分布,今天重点看多重继承的虚表内存分布,简单的说,继承几个类便有几个虚表,如下代码 class Drive : public Base1, public Base2, public B ...

  7. Java简介(4)-关键字

    abstract assert boolean break byte byte case catch char class const continue default do-while double ...

  8. CSU 1337(费马大定理)

      CSU 1337 Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu   Descrip ...

  9. Logger之Logger.getLogger(CLass)

    之前一直在使用System.out.println()来调试.但是用这种方式开发项目部署到生产环境,会因为众多的控制台输出降低应用的性能.这时候Log4J就成为可平衡开发和部署应用的利器了. 在项目中 ...

  10. 转:Mongodb中随机的查询文档记录

    简述,摘要:在实际应用场景中,几乎都会有随机获取数据记录的需求.而这个需求在Mongodb却不是很好实现,就目前而言,大致上有三种解决方案:1. 先计算出一个从0到记录总数之间的随机数,然后采用ski ...