# ng2-observable-events

> giving you DOM event observables as a directive that can be applied to any child element in your component

Latest version **1.0.0** (published 2016-07-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install ng2-observable-events
pnpm add ng2-observable-events
yarn add ng2-observable-events
bun add ng2-observable-events
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-07-23 |
| First published | 2016-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 15 |
| Known vulnerabilities | 0 (+22 in 4 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Nadav Sinai |
| Maintainers | Nadav Sinai |
| Keywords | angular2, directive, rxjs |

## Links

- npm: https://www.npmjs.com/package/ng2-observable-events
- Repository: https://github.com/nadavsinai/ng2-observable-events
- Homepage: https://github.com/nadavsinai/ng2-observable-events#readme
- Issues: https://github.com/nadavsinai/ng2-observable-events/issues
- npm.io page: https://npm.io/package/ng2-observable-events

## Dependencies (15)

- [rxjs](https://npm.io/package/rxjs.md) 5.0.0-beta.6
- [core-js](https://npm.io/package/core-js.md) ^2.4.0
- [zone.js](https://npm.io/package/zone.js.md) ^0.6.12
- [systemjs](https://npm.io/package/systemjs.md) 0.19.27
- [@angular/core](https://npm.io/package/@angular/core.md) 2.0.0-rc.4
- [@angular/http](https://npm.io/package/@angular/http.md) 2.0.0-rc.4
- [@angular/forms](https://npm.io/package/@angular/forms.md) 0.2.0
- [@angular/common](https://npm.io/package/@angular/common.md) 2.0.0-rc.4
- [@angular/router](https://npm.io/package/@angular/router.md) 3.0.0-beta.2
- [@angular/upgrade](https://npm.io/package/@angular/upgrade.md) 2.0.0-rc.4
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.3
- [@angular/compiler](https://npm.io/package/@angular/compiler.md) 2.0.0-rc.4
- [@angular/platform-browser](https://npm.io/package/@angular/platform-browser.md) 2.0.0-rc.4
- [@angular/router-deprecated](https://npm.io/package/@angular/router-deprecated.md) 2.0.0-rc.2
- [@angular/platform-browser-dynamic](https://npm.io/package/@angular/platform-browser-dynamic.md) 2.0.0-rc.4

## Recent versions

- 1.0.0 (latest) — 2016-07-23

## README

# Observable Events Directive

Angular 2 pushes the developer towards observable "stream" programming. 
This is modeled very nicely for state changes using inputs and the async pipe.
However getting dom events observables is a bit cumbersome if done right,I made this little helper to make it a little easier.

It is easy to use [Rx.Observable.fromEvent](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-fromEvent) constructor somewhere in your component code, 
however this will be against angular 2 paradigm of not accessing the DOM directly as for the first paramter you will need reference to a native DOM element.

My code uses [Rx.Observable.fromEventPattern](http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html#static-method-fromEventPattern), utilizing the renderer .listen method
 which goes though all the abstraction needed for both the webWorker and server use cases as well as the obvious browser use case.
 
 
##Use

- Add the exported ObservableEvents directive class to your directives array in your component or below it.
- use the ObsEvents='' attribute selector on the dom element you would like to monitor, the value should be the event type (without the "on") eg : ObsEvents="click"
- If you need more than one event observable you can separate multiple event names with a comma eg : ObsEvents="mousemove,mouseup,mousedown" 
- add a local template variable to the DOM node - #myObs='$' , the part that's set here is the $ in the value's place, myObs is just an example
- use @ViewChild('myObs') to recieve the exported observable to your component's class, remember it is only available after ngAfterViewInit hook has been called.

example code in src folder

---
_Source: https://npm.io/package/ng2-observable-events · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
