Created
June 27, 2016 07:01
-
-
Save tkssharma/580622742141f38fbe4d926af5bf7100 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 '@angular/core'; | |
import {DemoService} from './demo.service'; | |
@Component({ | |
selector: 'demo-app', | |
template:` | |
<h1>Angular2 HTTP Demo App</h1> | |
<h2>Foods</h2> | |
<div *ngIf="foods_error">An error occurred while loading the foods!</div> | |
<ul> | |
<li *ngFor="let food of foods">{{food.name}}</li> | |
</ul> | |
... | |
` | |
}) | |
export class AppComponent { | |
... | |
public foods_error:Boolean = false; | |
constructor(private _demoService: DemoService) { } | |
... | |
getFoods() { | |
this._demoService.getFoods().subscribe( | |
data => { this.foods = data}, | |
err => { this.foods_error = true } | |
); | |
} | |
getBooksAndMovies() { | |
this._demoService.getBooksAndMovies().subscribe( | |
data => { | |
this.books = data[0] | |
this.movies = data[1] | |
} | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment