[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里面的内容不免都简单些,翻 ...
随机推荐
- List、Set、Map的使用
1.List(接口) List接口的特点: a.List接口可以存放任意数据,且在接口中,数据可以重复. b.List中提供了高效的插入和移除多个元素的方法. List常用的子类 a.ArrayLis ...
- ORACLE_DBA管理脚本
SYS @ prod >col index_name for a10 SYS @ prod >col table_name for a10 SYS @ prod >col start ...
- Xcode 的正确打开方式——Debugging(转)
转自CocoaChina http://www.cocoachina.com/ios/20150225/11190.html 程序员日常开发中有大量时间都会花费在 debug 上,从事 iOS 开发不 ...
- cer, pfx 创建,并且读取公钥/密钥,加解密 (C#程序实现)
PKI技术(public key infrastructure)里面,cer文件和pfx文件是很常见的.通常cer文件里面保存着公钥以及用户的一些信息,pfx里面则含有私钥和公钥. 用makecert ...
- java_reflect_03
关于反射在annotation中的使用,这也是本次我个人学习反射的主要目的 关于什么是annotation后续我也会整理一下,现在只大致介绍一下 一,Annotation(注解)简介: 注解大家印象最 ...
- 141 Linked List Cycle(判断链表是否有环Medium)
题目意思:链表有环,返回true,否则返回false 思路:两个指针,一快一慢,能相遇则有环,为空了没环 ps:很多链表的题目:都可以采用这种思路 /** * Definition for singl ...
- 移除IOS下按钮的原生样式
写WAP页面的时候 一定要加上这组样式,以避免在IOS下面按钮被系统原生样式影响 input,textarea {outline-style:none;-webkit-appearance:none ...
- 深入理解javascript闭包(一)
原文转自脚本之家(http://www.jb51.net/article/24101.htm) 闭包(closure)是Javascript语言的一个难点,也是它的特色,很多高级应用都要依靠闭包实现. ...
- jquery 与其他库冲突解决方案
var j = jQuery.noConflict(); j("div p").hide(); // 基于 jQuery 的代码 $("content").st ...
- WEB兼容性之JS
1. 获取iframe的window对象 //三种方法 window.iframeName window.frames[iframeName] document.getElementById(ifra ...