I want to save and access to the Angular2 object but I am getting undefined as value. I am getting a object but this not accessible such as array. How can I do it as array?
Node.js api.js
api.get('/getData', function(req, res){
res.send({name:'test'})
});
Dataservice PassProfileDataService.ts
import {Component, Injectable} from '@angular/core'
import { Http} from "@angular/http";
@Injectable()
export class PassProfileDataService {
constructor(private http: Http) {}
getItems(){
return this.http.get('/api/getData').map((res:any) => res);
}
}
Component which consumes the service
import {Component, Input, OnInit} from '@angular/core';
import {PassProfileDataService} from '../common/PassProfileDataService';
@Component({
styleUrls:['/assets/css/bootstrap.css', '/assets/css/profile.css'],
selector: "profile",
templateUrl: `client/components/profile/profile.component.html`
})
export class ProfileComponent implements OnInit {
items:any;
constructor(private _sharedService: PassProfileDataService){}
ngOnInit(){
this.items = this._sharedService.getItems();
console.log(this.items + ' test');
}
}
The view component profile.component.html
<div *ngFor="let i of items">
{{i.name}}
</div>
I am getting following Exception:
core.umd.js:3462 EXCEPTION: Cannot find a differ supporting object '[object Object]' of type 'object'. NgFor only supports binding to Iterables such as Arrays.