Im trying to display a list of item names from a rest api. I call map on the response observable and subscribe to get the parsed items object.
How can I attach the object to the component and display list of item.name on the html template?
import { Component, bootstrap } from 'angular2/angular2';
import { Http, HTTP_PROVIDERS } from 'angular2/http';
@Component({
selector: 'item-app',
viewProviders: [HTTP_PROVIDERS],
templateUrl: 'app/content.html'
})
class ItemsComponent {
items: Object;
constructor(http: Http) {
http.get('http://localhost:3000/api/items')
.map(response => response)
.subscribe(
items => this.items = items
);
}
}
<ul>
<li *ng-for="#item of items">
{{ item.name }}
</li>
</ul>