2015-12-14 01:29:37 -05:00
|
|
|
// #docplaster
|
2015-12-07 16:31:26 -05:00
|
|
|
import {Directive, Output, ElementRef, EventEmitter} from 'angular2/core';
|
|
|
|
|
2016-01-10 20:07:19 -05:00
|
|
|
@Directive({selector:'[myClick]'})
|
2015-12-07 16:31:26 -05:00
|
|
|
export class MyClickDirective {
|
2015-12-14 01:29:37 -05:00
|
|
|
// #docregion my-click-output-1
|
2015-12-07 16:31:26 -05:00
|
|
|
@Output('myClick') clicks = new EventEmitter<string>();
|
2015-12-14 01:29:37 -05:00
|
|
|
// #enddocregion my-click-output-1
|
2015-12-07 16:31:26 -05:00
|
|
|
constructor(el: ElementRef){
|
|
|
|
el.nativeElement
|
|
|
|
.addEventListener('click', (event:Event) => {
|
|
|
|
this.clicks.emit('Click!');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-14 01:29:37 -05:00
|
|
|
// #docregion my-click-output-2
|
2015-12-07 16:31:26 -05:00
|
|
|
@Directive({
|
2015-12-14 01:29:37 -05:00
|
|
|
// #enddocregion my-click-output-2
|
2015-12-13 23:10:03 -05:00
|
|
|
selector:'[myClick2]',
|
2015-12-14 01:29:37 -05:00
|
|
|
// #docregion my-click-output-2
|
2015-12-07 16:31:26 -05:00
|
|
|
outputs:['clicks:myClick']
|
|
|
|
})
|
2015-12-14 01:29:37 -05:00
|
|
|
// #enddocregion my-click-output-2
|
2015-12-07 16:31:26 -05:00
|
|
|
export class MyClickDirective2 {
|
|
|
|
clicks = new EventEmitter<string>();
|
|
|
|
constructor(el: ElementRef){
|
|
|
|
el.nativeElement
|
|
|
|
.addEventListener('click', (event:Event) => {
|
|
|
|
this.clicks.emit('Click!');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|