Created
December 10, 2015 12:50
-
-
Save johnlindquist/3fe18725fc67e2177b27 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' | |
import {Subject} from "rxjs"; | |
@Component({ | |
selector: 'app', | |
template: ` | |
<input type="number" [ngFormControl]="numControl" /> | |
{{(contact | async)?.name?.first}} | |
{{(contact | async)?.name?.last}} | |
` | |
}) | |
export class App { | |
numControl = new Control(); | |
contact = new Subject(); | |
constructor(http:Http){ | |
this.numControl | |
.valueChanges | |
.switchMap(id => http.get('http://localhost:3000/people/' + id) | |
.map(res => res.json())) | |
.subscribe(this.contact); | |
this.numControl.updateValue(0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment