Skip to content

Instantly share code, notes, and snippets.

@johnlindquist
Created December 10, 2015 01:37
Show Gist options
  • Save johnlindquist/1b6dcf90dfd3cb2b3e5f to your computer and use it in GitHub Desktop.
Save johnlindquist/1b6dcf90dfd3cb2b3e5f to your computer and use it in GitHub Desktop.
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