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

  1. [Angular 2] Handling Click Events with Subjects

    While Angular 2 usually uses event handlers to manage events and RxJS typically uses Observable.from ...

  2. [LeetCode] Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  3. 【leetcode】Merge Intervals(hard)

    Given a collection of intervals, merge all overlapping intervals. For example,Given [1,3],[2,6],[8,1 ...

  4. 【LeetCode】56. Merge Intervals

    Merge Intervals Given a collection of intervals, merge all overlapping intervals. For example,Given  ...

  5. [LeetCode] 435. Non-overlapping Intervals 非重叠区间

    Given a collection of intervals, find the minimum number of intervals you need to remove to make the ...

  6. Android 自定义title 之Action Bar

    Android 自定义title 之Action Bar 2014-06-29  飞鹰飞龙...  摘自 博客园  阅 10519  转 25 转藏到我的图书馆   微信分享:   Action Ba ...

  7. 【Android】Android之Action Bar

    Action Bar是在窗口上指示用户位置的组件,同时给用户提供导航和操作.使用Action Bar可以让你的应用在不同配置的屏幕上看起来比较一致.在开始之前,先了解一些相关的术语: Action B ...

  8. ActionBar官方教程(4)给ActionBar添加操作项及它们的事件处理

    Adding Action Items The action bar provides users access to the most important action items relating ...

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

随机推荐

  1. 【转】block一点也不神秘————如何利用block进行回调

    我们在开发中常常会用到函数回调,你可以用通知来替代回调,但是大多数时候回调是比通知方便的,所以何乐而不为呢?如果你不知道回调使用的场景,我们来假设一下: 1.我现在玩手机 2.突然手机没有电了 3.我 ...

  2. json+一般处理程序读取数据库数据

    一般处理程序的语法结构 string jsoncallback = context.Request["jsoncallback"]; 声明变量 前台传值使用        stri ...

  3. java_annotation_01

    一,Annotation简介 J2SE5.0提供了很多新的我,其中一个很重要的我就是对元数据的支持,在J2SE5.0中,这种元数据被称为注释,通过使用注释,程序开发人员可以在不改变原有逻辑的情况下,在 ...

  4. 如何用angularjs制作一个完整的表格之四__自定义ng-model标签的属性使其支持input之外的html元素

    有的时候我们需要为非input类型的元素添加ng-model来实现双向的数据绑定,从而减少冗余代码,那么可以尝试一下的方式 例如:我页面中使用了contenteditable这个属性来实现用户可直接编 ...

  5. Delphi-CompareStr 函数

    函数名称 CompareStr 所在单元 System.SysUtils 函数原型 function CompareStr(const S1, S2: string): Integer; 函数功能 比 ...

  6. python学习之旅:array 转 list

    最近学习python,记录学习的点滴. >>> import numpy as np >>> a = np.array([[1,2],[3,4]]) >> ...

  7. ppt怎么换背景图片|PPT换背景设置方法

    PPT怎么换背景?PPT背景可谓是PPT幻灯片的灵魂,优美绚丽的PPT背景能为自己做的PPT幻灯片锦上添花.今天,格子啦小编就教大家PPT换背景的方法,让你不再羡慕别人所做PPT的美丽背景,也可以自己 ...

  8. 【学习笔记】【oc】指针

    1.取一个变量的值,可通过直接与间接的方式 直接:访问变量 间接:通过变量的内存地址来获取变量的值. 存放内存地址的变量就是指针变量. 2.定义指针变量的语法:类型* 变量名 &:取地址运算符 ...

  9. 魅蓝3s adb interface 找不到驱动程序

    完全照搬大神的步骤就ok啦,,自己记录下,方便以后查找 Win7 x64 Eclipse无法识别手机 / adb interface有黄色感叹号,无法识别 http://blog.csdn.net/z ...

  10. maven学习心得

    心得:这几天一直在研究maven的配置,还真是伤心啊,网上资料不多,而且问题不断.确实很让人头疼 背景:之所以学习maven是因为我们需要一键部署,我们项目是已经差不多完成了,是eclipse的web ...