How to read [object object] using angular-2

@el0zahaby You must convert from json string to a javascript object first:

@Component(...)
export class MyPage {

	public jsonObject: any;

	private retrieveJson() {
		let jsonData: string = this.myService.getJsonString();
		this.jsonObject = JSON.parse(jsonData);
	}
}

and then:

<ion-item text-wrap *ngFor="let item of jsonObject" >

A better approach is convert to an object in the service itself. If you are doing an http request you can do something like:

my.service.ts:

public myServiceMethod(): Observable<MyObject> {
	return this.http.get('[url]').map(
		res => res.json() // Transform the JSON string in an object
	);
}

my.component.ts:

private retrieveJson() {
	this.myService.myServiceMethod().subscribe(
		jsonObject => this.jsonObject = jsonObject
	);
}

Update

Now that I’ve seen you updated code, I don’t know what your method httpProvider.getJsonData() does, but I think that you should do what I explained above about the http call (converting the string to an object)

1 Like