[Angular 2] Handling Clicks and Intervals Together with Merge
Observable.merge allows you take two different source streams and use either one of them to make changes to the same state of your data. This lesson shows how you can use a stream of clicks and an interval stream and use either one to update the clock.
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/interval';
import 'rxjs/add/observable/merge';
import 'rxjs/add/operator/map';
import {Subject} from 'rxjs/Subject';
@Component({
selector: 'app',
template: `
<button (click)="click$.next()">Update</button>
<h1>{{clock | async | date: 'yMMMMEEEEdjms'}}</h1>
`
})
class App {
click$ = new Subject();
clock;
constructor(){
this.clock = Observable.merge(
Observable.interval(),
this.click$
).map( () => new Date());
}
}
bootstrap(App);
So the logic is both
- every 5 seconds to update the clock
- when click the button to update the clock
SO there use logic "OR" --> merge() to do that
[Angular 2] Handling Clicks and Intervals Together with Merge的更多相关文章
- [Angular 2] Handling Click Events with Subjects
While Angular 2 usually uses event handlers to manage events and RxJS typically uses Observable.from ...
- [LeetCode] Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- 【leetcode】Merge Intervals(hard)
Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...
- 【LeetCode】56. Merge Intervals
Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given ...
- [LeetCode] 435. Non-overlapping Intervals 非重叠区间
Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...
- Android 自定义title 之Action Bar
Android 自定义title 之Action Bar 2014-06-29 飞鹰飞龙... 摘自 博客园 阅 10519 转 25 转藏到我的图书馆 微信分享: Action Ba ...
- 【Android】Android之Action Bar
Action Bar是在窗口上指示用户位置的组件,同时给用户提供导航和操作.使用Action Bar可以让你的应用在不同配置的屏幕上看起来比较一致.在开始之前,先了解一些相关的术语: Action B ...
- ActionBar官方教程(4)给ActionBar添加操作项及它们的事件处理
Adding Action Items The action bar provides users access to the most important action items relating ...
- Android设计和开发系列第二篇:Action Bar(Develop—API Guides)
Action Bar IN THIS DOCUMENT Adding the Action Bar Removing the action bar Using a logo instead of an ...
随机推荐
- webservice调用接口,接口返回数组类型
1. 其中sendSyncMsg1接口是方法名,Vector实现了List接口,xml是sendSyncMsg1的方法形参 Service service = new Service(); Call ...
- 自由创造属于你的H5内容
在这里,你可以自由创造属于你的H5内容 mark下 http://www.ih5.cn/
- centos 给鼠标右击添加 “打开终端” 菜单项
1.以root身份在终端执行如下命令 yum -y install nautilus-open-terminal 2.重启操作系统 shutdown -r now
- 【USACO 1.3.2】修理牛棚
[描述] 在一个夜黑风高,下着暴风雨的夜晚,farmer John的牛棚的屋顶.门被吹飞了. 好在许多牛正在度假,所以牛棚没有住满. 牛棚一个紧挨着另一个被排成一行,牛就住在里面过夜. 有些牛棚里有牛 ...
- android布局2
Android功能强大,界面华丽,但是众多的布局属性就害苦了开发者,下面这篇文章结合了网上不少资料. 第一类:属性值为true或false android:layout_centerHrizontal ...
- 广东移动NGBOSS系统话费查询
基于很多客户的需要 现承接广东移动NGBOSS华为系统的各项功能开发 承接广东深圳.佛山.东莞.广州.惠州.汕头.湛江移动NGBOSS的全球通开户,批量话费查询.缴费,号码导出等功能开发. 有需要者联 ...
- FLEX 网格布局及响应式处理
上一篇文章用Flex实现BorderLayout,这一章我们来实现常用的网格布局和响应式处理. 首先我们定义HTML结构,主Box为grid,每项为grid-cell,下面就是我们HTML代码结构. ...
- C语言内存对齐原理
一.什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的内存地址访问,这 ...
- Python学习6.1_函数参数及参数传递
大多数编程语言都绕不开一个名词,那就是--函数(function).而函数很重要的部分则是参数(arguments)的使用.Python的参数传递总体来说是根据位置,传递对应的参数.阐述如下: 1.位 ...
- 安装mysql-python报错
运行: pip install mysql-python报错如下: Downloading/unpacking MYSQL-python Downloading MySQL-python-1.2.5. ...