angularjs - looping json object in ng-repeat -
i have json object containing {"id":1,"name":"name1"}
rest api , want display name property in list using ng-repeat. below have in page:
<ion-item ng-repeat="p in names"> {{p.name}} </ion-item>
it not display above code , when change {{ p.name }}
{{ names }}
displays {"id":1,"name":"name1"}
. iterate , each properties?
is json object array or object?
/* array - can ng-repeat on */ names = [{"id":1, "name":"name1"}] /* object - cannot ng-repeat on */ names = {"id":1, "name":"name1"}
if object, ng-repeat
not able iterate.
you can see example of in action here.
answering question below user3514822
in case of comment below json.parse
return array of objects or single object.
var response = { "userlist": [ "{\"id\":1,\"name\":\"alex\"}" ] }; $scope.names=json.parse( response.userlist ); if( object.prototype.tostring.call( $scope.names ) !== '[object array]' ) { $scope.names = [ $scope.names ]; }
after doing ng-repeat
should work have defined $scope.names
should array.
Comments
Post a Comment