[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 ...
随机推荐
- [转] 关于UIView
[转载] 原文地址 :http://blog.csdn.net/itianyi/article/details/8982518 UIView是开发中使用得最多的控件了,深入的理解很有必要. UIVie ...
- MySQL 管理
MySQL 管理 启动及关闭 MySQL 服务器 首先,我们需要通过以下命令来检查MySQL服务器是否启动: ps -ef | grep mysqld 如果MySql已经启动,以上命令将输出mysql ...
- hibernate_validator_05
校验约束 一,认识Validator---Validation中最主要的接口 1.怎么获取一个Validator--Validation.buildDefaultValidatorFactory() ...
- python challenge 16
前情回顾:上一篇 第16关地址 打开16关,又是一张奇奇怪怪很多点点的图片,应该又是与PIL库有关的. 页面的标题是:let me get this straight.这是英语中的一句俚语,意思是让我 ...
- margin-top在IE与其他浏览器下的不同
两个box,box1嵌套box2, box2使用margin-top在IE下与其他浏览器不同.待整理
- MySQL Server 5.6 解压版安装配置
MySQL解压版下载地址为: http://dev.mysql.com/downloads/mysql/5.6.html#downloads 安装及配置步骤: ①将MySQL的zip包解压到路径C:\ ...
- 关于PHPstorm 使用技巧
慢慢更新,一点点积累,都是自己在使用中遇到的问题 设置:(2016.4.15) 1:注释模板,phpstorm 有非常强大的注释模板,可以根据自己的需求随时更改,并设置快捷键,非常方便 新文件注释 P ...
- jQuery获取JSON格式数据方法
getJSON方法: jQuery.getJSON(url,data,success(data,status,xhr)) $("button").click(function(){ ...
- UVA - 12627 Erratic Expansion 奇怪的气球膨胀 (分治)
紫书例题p245 Piotr found a magical box in heaven. Its magic power is that if you place any red balloon i ...
- Oracle开启归档
#查看数据库是否为归档模式select name ,log_mode from v$database; #改变归档模式到非归档模式shutdown normal/immediate; #关闭数据库st ...