feat(events): add support for global events

Fixes #1098
Closes #1255
This commit is contained in:
Marc Laval
2015-04-02 15:56:58 +02:00
parent 7c95cea3a8
commit b96e560c8d
27 changed files with 414 additions and 103 deletions

View File

@ -367,6 +367,8 @@ export class Directive extends Injectable {
* - `event1`: the DOM event that the directive listens to.
* - `statement`: the statement to execute when the event occurs.
*
* To listen to global events, a target must be added to the event name.
* The target can be `window`, `document` or `body`.
*
* When writing a directive event binding, you can also refer to the following local variables:
* - `$event`: Current event object which triggered the event.
@ -380,6 +382,7 @@ export class Directive extends Injectable {
* @Directive({
* hostListeners: {
* 'event1': 'onMethod1(arguments)',
* 'target:event2': 'onMethod2(arguments)',
* ...
* }
* }
@ -387,19 +390,22 @@ export class Directive extends Injectable {
*
* ## Basic Event Binding:
*
* Suppose you want to write a directive that triggers on `change` hostListeners in the DOM. You would define the event
* binding as follows:
* Suppose you want to write a directive that triggers on `change` events in the DOM and on `resize` events in window.
* You would define the event binding as follows:
*
* ```
* @Decorator({
* selector: 'input',
* hostListeners: {
* 'change': 'onChange($event)'
* 'change': 'onChange($event)',
* 'window:resize': 'onResize($event)'
* }
* })
* class InputDecorator {
* onChange(event:Event) {
* }
* onResize(event:Event) {
* }
* }
* ```
*