Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created June 27, 2016 07:01
Show Gist options
  • Save tkssharma/580622742141f38fbe4d926af5bf7100 to your computer and use it in GitHub Desktop.
Save tkssharma/580622742141f38fbe4d926af5bf7100 to your computer and use it in GitHub Desktop.
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