Am trying to converting some strings from json response to number. for example
zipcode: "92998-3874" to 92998-3874. came across this SO. but don't where its getting failed. followed by that i need to loop it in my view but am facing below error in stack blitz console.
ERROR
Error: Cannot find a differ supporting object '[object Object]' of type 'Clementina DuBuque'. NgFor only supports binding to Iterables such as Arrays.
Unable to display error. Open your browser's console to view.
so far:
export class AppComponent {
name = 'Angular';
private _userList = [];
private _userListAddress:any = [];
_sampleURL = 'https://jsonplaceholder.typicode.com/users';
constructor(private _http: HttpClient) { }
_loadData() {
this._http.get<any[]>(this._sampleURL).subscribe(data => {
this._userList = data;
this._userListAddress = data[0].address.suite;
console.log(this._userList);
for (var _address in this._userList) {
this._userListAddress = this._userList[_address];
console.log('address',
parseInt(this._userListAddress.address.zipcode));
/*
//below snippet is used to convert strings to num
[].forEach.call(this._userList, function (a, b) {
[].forEach.call(Object.keys(a), function (c) {
if (!isNaN(this._userList[b][c]))
this._userList[b][c] = +this._userList[b][c];
});
});
console.log(this._userList); */
}
}
)
}
}
<button (click)="_loadData()">Load data</button>
<div *ngFor="let list of _userList">
<ul>
<li>{{list.address.zipcode}}</li>
</ul>
<div *ngFor="let addresList of _userListAddress">
<ul>
<li>{{addresList.address.zipcode}}</li>
</ul>
</div>
</div>
where am doing wrong or suggest better way to achieve this. Helps much appreciated.