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
|
2016-01-19 02:54:27 -05:00
|
|
|
@Output('myClick') clicks = new EventEmitter<string>(); // @Output(alias) propertyName = ...
|
2015-12-14 01:29:37 -05:00
|
|
|
// #enddocregion my-click-output-1
|
2016-01-19 02:54:27 -05:00
|
|
|
|
2015-12-07 16:31:26 -05:00
|
|
|
constructor(el: ElementRef){
|
|
|
|
el.nativeElement
|
|
|
|
.addEventListener('click', (event:Event) => {
|
2016-01-19 02:54:27 -05:00
|
|
|
this._toggle = !this._toggle;
|
|
|
|
this.clicks.emit(this._toggle ? 'Click!' : '');
|
2015-12-07 16:31:26 -05:00
|
|
|
});
|
|
|
|
}
|
2016-01-19 02:54:27 -05:00
|
|
|
_toggle = false;
|
2015-12-07 16:31:26 -05:00
|
|
|
}
|
|
|
|
|
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
|
2016-01-19 02:54:27 -05:00
|
|
|
outputs:['clicks:myClick'] // propertyName:alias
|
2015-12-07 16:31:26 -05:00
|
|
|
})
|
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>();
|
2016-01-19 02:54:27 -05:00
|
|
|
|
2015-12-07 16:31:26 -05:00
|
|
|
constructor(el: ElementRef){
|
|
|
|
el.nativeElement
|
|
|
|
.addEventListener('click', (event:Event) => {
|
2016-01-19 02:54:27 -05:00
|
|
|
this._toggle = !this._toggle;
|
|
|
|
this.clicks.emit(this._toggle ? 'Click2!' : '');
|
2015-12-07 16:31:26 -05:00
|
|
|
});
|
|
|
|
}
|
2016-01-19 02:54:27 -05:00
|
|
|
_toggle = false;
|
2015-12-07 16:31:26 -05:00
|
|
|
}
|