Created
December 10, 2015 01:37
-
-
Save johnlindquist/1b6dcf90dfd3cb2b3e5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Component} from "angular2/core"; | |
import {Control} from "angular2/common"; | |
import {Http} from "angular2/http"; | |
@Component({ | |
selector:`contact-search`, | |
template:`<div> | |
<input [ng-form-control]="searchInput"/> | |
<div *ngFor="#contact of results | async"> | |
<img [src]="contact.avatar"/> | |
<h3>{{contact.name.first}} {{contact.name.last}}</h3> | |
<h5>{{contact.email}}</h5> | |
</div> | |
</div>` | |
}) | |
export class ContactSearch{ | |
searchInput = new Control(); | |
results; | |
constructor(public http:Http){ | |
this.results = this.searchInput | |
.valueChanges | |
.debounceTime(250) | |
.switchMap(value => this.search(value)); | |
} | |
search(query){ | |
return this.http | |
.get('http://localhost:3000/people?q=' + query) | |
.map((res:any) => res.json()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment