Created
June 27, 2016 05:52
-
-
Save tkssharma/e1d8e82309946ecd5d92c5050114faad 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
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