Skip to content

Instantly share code, notes, and snippets.

@tkssharma
Created June 27, 2016 05:52
Show Gist options
  • Save tkssharma/e1d8e82309946ecd5d92c5050114faad to your computer and use it in GitHub Desktop.
Save tkssharma/e1d8e82309946ecd5d92c5050114faad to your computer and use it in GitHub Desktop.
class AppComponent {
products: Array = [];
constructor(private http: Http) {
this.http.get('/products')
.map(res => res.json())
.subscribe(
data => {
if (Array.isArray(data)){
this.products=data;
} else{
this.products.push(data);
}
},
err =>
console.log("Can't get products. Error code: %s, URL: %s ", err.status, err.url),
() => console.log('Product(s) are retrieved')
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment