| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  | // #docregion
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { Component }        from '@angular/core'; | 
					
						
							|  |  |  | import { Observable }       from 'rxjs/Observable'; | 
					
						
							| 
									
										
										
										
											2016-02-02 11:22:48 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | import { WikipediaService } from './wikipedia.service'; | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | @Component({ | 
					
						
							|  |  |  |   selector: 'my-wiki', | 
					
						
							|  |  |  |   template: `
 | 
					
						
							|  |  |  |     <h1>Wikipedia Demo</h1> | 
					
						
							|  |  |  |     <p><i>Fetches after each keystroke</i></p> | 
					
						
							| 
									
										
										
										
											2016-02-02 02:27:52 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  |     <input #term (keyup)="search(term.value)"/> | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  |     <ul> | 
					
						
							| 
									
										
										
										
											2016-04-29 01:36:35 +01:00
										 |  |  |       <li *ngFor="let item of items | async">{{item}}</li> | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  |     </ul> | 
					
						
							|  |  |  |   `,
 | 
					
						
							| 
									
										
										
										
											2016-08-09 17:38:25 +01:00
										 |  |  |   providers: [WikipediaService] | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  | }) | 
					
						
							|  |  |  | export class WikiComponent { | 
					
						
							| 
									
										
										
										
											2016-06-08 01:06:25 +02:00
										 |  |  |   items: Observable<string[]>; | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |   constructor (private wikipediaService: WikipediaService) {} | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   search (term: string) { | 
					
						
							| 
									
										
										
										
											2016-05-03 14:06:32 +02:00
										 |  |  |     this.items = this.wikipediaService.search(term); | 
					
						
							| 
									
										
										
										
											2015-12-01 12:15:14 +01:00
										 |  |  |   } | 
					
						
							|  |  |  | } |