Created
March 17, 2016 02:22
-
-
Save johnlindquist/5b8a1111cda507ea3d05 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 {bootstrap} from 'angular2/platform/browser'; | |
import 'rxjs/Rx'; | |
import {HTTP_PROVIDERS, Http} from 'angular2/http'; | |
@Component({ | |
selector: 'app', | |
template: ` | |
<ul *ngFor="#person of people | async"> | |
{{person.name}} | |
</ul> | |
` | |
}) | |
export class App { | |
people = this.http | |
.get('http://swapi.co/api/people') | |
.map(res => res.json().results); | |
constructor(public http:Http){} | |
} | |
bootstrap(App, [HTTP_PROVIDERS]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Prefer:
Reason: Its clear to see from the constructor any significant initialization. This is just the way I've done it in the past when
$http.get
would actually send an XHR.PS: It this was React I would be looking at
componentDidMount
: https://facebook.github.io/react/docs/component-specs.html#mounting-componentdidmount (mentions XHRs should happen here) < This might be a completely useless piece of information but explains where I am coming from 🌹