[Angular 2] Handling Click Events with Subjects
While Angular 2 usually uses event handlers to manage events and RxJS typically uses Observable.fromEvent, a good practice when using Angular 2 and RxJS combined is to use Subjects and push the value through each event so that you can use it as part of your stream.
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
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();
public clock;
constructor(){
this.clock = this.click$.map( () => new Date());
}
}
bootstrap(App);
So here create a click$ subject, every time you click the button, it will map to a current date value.
[Angular 2] Handling Click Events with Subjects的更多相关文章
- Google C++单元测试框架GoogleTest---Extending Google Test by Handling Test Events
Google TestExtending Google Test by Handling Test Events Google测试提供了一个事件侦听器API,让您接收有关测试程序进度和测试失败的通知. ...
- [Cycle.js] Read effects from the DOM: click events
So far we only had effects that write something to the external world, we are not yet reading anythi ...
- [Angular Directive] 3. Handle Events with Angular 2 Directives
A @Directive can also listen to events on their host element using @HostListener. This allows you to ...
- [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 cha ...
- Button's four click events
第一种:内部类的方式 1 package com.example.phonedialer; 2 3 import com.example.click2.R; 4 5 import android.ne ...
- [Angular] Subscribing to router events
In our root component, one thing we can do is subscribe to Router events, and do something related t ...
- Android用户界面布局(layouts)
Android用户界面布局(layouts) 备注:view理解为视图 一个布局定义了用户界面的可视结构,比如activity的UI或是APP widget的UI,我们可以用下面两种方式来声明布局: ...
- Pro Android 4 第六章 构建用户界面以及使用控件(一)
目前为止,我们已经介绍了android的基础内容,但是还没开始接触用户界面(UI).本章我们将开始探讨用户界面和控件.我们先讨论一下android中UI设计的一般原理,然后我们在介绍一下an ...
- [翻译]API Guides - Layouts
官方文档地址:http://developer.android.com/guide/topics/ui/declaring-layout.html PS:API Guides里面的内容不免都简单些,翻 ...
随机推荐
- CSS 布局Float 【0】
float是 css 样式的定位属性.我们在印刷排版中,文本可以按照需要围绕图片.一般把这种方式称为“文本环绕”.在网页设计中,应用了CSS的float属性的页面元素就像在印刷布局里面的被文字包围的图 ...
- Mysql软删除
所谓软删除(Soft Deleting),即在删除数据表中的数据时,并不直接将其从数据表中删除,而是将其标志为删除,即在每张表中设置一个删除字段(如:IsDeleted)等,默认情况下其值为0,及未删 ...
- 用JAVA给JSON进行排版
之前听到朋友的面试题,是如何对JSON进行排版,于是就写了一个Demo,觉得挺有意思的,就贴出来了. 这个就是记录缩进来输出,大家也可以尝试一下其他更好算法来进行输出. 功能:可以把一行的JSON字符 ...
- Qt中如何在QCursor移动的时候不触发moveEvent
有时候有这样的需求,比如想对全局光标进行一次setPos(),但这个时候又不想触发消息队列触发mouseMoveEvent,这个时候就可以这么做. myWidget->clearFocus(); ...
- 再谈CMake与RPATH
之前写过一篇<探讨CMake中关于RPATH的使用>,只要针对的方面是在编译生成之后(不包括安装的make install)如何去除RPATH的问题.今天给大家主要介绍一下如何让CMake ...
- Thinkphp发布文章获取第一张图片为缩略图实现方法
正则匹配图片地址获取第一张图片地址 此为函数 在模块或是全局Common文件夹中的function.php中 /** * [getPic description] * 获取文本中首张图片地址 * @p ...
- php 5.2 版本isset()方法小坑
PHP 5.2.17p1 (cli) (built: May 28 2015 16:15:30)Copyright (c) 1997-2010 The PHP GroupZend Engine v2. ...
- python之7-2类的继承与多态
类的继承的意思就如同父子关系一样,这个儿子继承了父亲的一切,但是在某些地方(属性)相同的时候,儿子的属性大于老子的属性(覆盖),最底层类,总会继承最接近它的那个类的属性init 类的多态总是和继承相连 ...
- Oracle中批量插入
为了防止OracleConnection的重复打开和关闭,使用begin end:将sql语句包在里面,然后一次性执行提高插入的效率. 下面代码中要插入的数据在list集合中,如果list集合的cou ...
- Linux_hadoop_install
1. Build Linux env my env is VM RedHat Linux 6.5 64bit set fixed IP vim /etc/sys ...