| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #docplaster
 | 
					
						
							| 
									
										
										
										
											2016-04-27 11:28:22 -07:00
										 |  |  | import {Directive,  Output, ElementRef, EventEmitter} from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-10 17:07:19 -08:00
										 |  |  | @Directive({selector:'[myClick]'}) | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | export class MyClickDirective { | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  |   // #docregion my-click-output-1
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |   @Output('myClick') clicks = new EventEmitter<string>(); //  @Output(alias) propertyName = ...
 | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  |  // #enddocregion my-click-output-1
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |   constructor(el: ElementRef){ | 
					
						
							|  |  |  |     el.nativeElement | 
					
						
							|  |  |  |       .addEventListener('click', (event:Event) => { | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |         this._toggle = !this._toggle; | 
					
						
							|  |  |  |         this.clicks.emit(this._toggle ? 'Click!' : ''); | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |   _toggle = false; | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #docregion my-click-output-2
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | @Directive({ | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #enddocregion my-click-output-2
 | 
					
						
							| 
									
										
										
										
											2015-12-13 20:10:03 -08:00
										 |  |  |   selector:'[myClick2]', | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #docregion my-click-output-2
 | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |   outputs:['clicks:myClick']  // propertyName:alias
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | }) | 
					
						
							| 
									
										
										
										
											2015-12-13 22:29:37 -08:00
										 |  |  | // #enddocregion my-click-output-2
 | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | export class MyClickDirective2 { | 
					
						
							|  |  |  |   clicks = new EventEmitter<string>(); | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |   constructor(el: ElementRef){ | 
					
						
							|  |  |  |     el.nativeElement | 
					
						
							|  |  |  |       .addEventListener('click', (event:Event) => { | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |         this._toggle = !this._toggle; | 
					
						
							|  |  |  |         this.clicks.emit(this._toggle ? 'Click2!' : ''); | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  |       }); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2016-01-18 23:54:27 -08:00
										 |  |  |   _toggle = false;   | 
					
						
							| 
									
										
										
										
											2015-12-07 13:31:26 -08:00
										 |  |  | } |