| 
									
										
										
										
											2016-03-16 18:01:33 +02:00
										 |  |  | import { | 
					
						
							|  |  |  |   Attribute, | 
					
						
							|  |  |  |   Component, | 
					
						
							|  |  |  |   ElementRef, | 
					
						
							|  |  |  |   Inject, | 
					
						
							|  |  |  |   Optional, | 
					
						
							|  |  |  |   Query, | 
					
						
							|  |  |  |   QueryList | 
					
						
							| 
									
										
										
										
											2016-04-27 11:28:22 -07:00
										 |  |  | } from '@angular/core'; | 
					
						
							| 
									
										
										
										
											2016-03-16 18:01:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | // #docregion
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'hero-title', | 
					
						
							|  |  |  |   template: `
 | 
					
						
							|  |  |  |     <h1>{{titlePrefix}} {{title}}</h1> | 
					
						
							|  |  |  |     <button (click)="ok()">OK</button> | 
					
						
							|  |  |  |     <ng-content></ng-content> | 
					
						
							|  |  |  |   `
 | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class TitleComponent { | 
					
						
							|  |  |  |   constructor( | 
					
						
							|  |  |  |     @Inject('titlePrefix') | 
					
						
							|  |  |  |     @Optional() | 
					
						
							|  |  |  |       private titlePrefix:string, | 
					
						
							|  |  |  |     @Attribute('title') | 
					
						
							|  |  |  |       private title:string, | 
					
						
							|  |  |  |     @Query('okMsg') | 
					
						
							|  |  |  |       private msg:QueryList<ElementRef>) { | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   ok() { | 
					
						
							|  |  |  |     let msgEl = | 
					
						
							|  |  |  |       this.msg.first.nativeElement; | 
					
						
							|  |  |  |     msgEl.textContent = 'OK!'; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | // #enddocregion
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'hero-di-inject-additional', | 
					
						
							|  |  |  |   template: `<hero-title title="Tour of Heroes">
 | 
					
						
							|  |  |  |     <span #okMsg class="ok-msg"></span> | 
					
						
							|  |  |  |   </hero-title>`, | 
					
						
							|  |  |  |   directives: [TitleComponent] | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | export class AppComponent { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |