Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng2-observable-events

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng2-observable-events

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

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

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 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, 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

Keywords

FAQs

Package last updated on 23 Jul 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc