How to use ng-repeat in an object list?

Asked

Viewed 1,293 times

1

How to use ng-repeat in the Region attribute of the object?

Example: ng-repeat="item in objeto.RegioesFilhas

Object:

   var objeto = {
       "DescricaoRegiaoVaga": "",
       "IdCidadeCorreios": "1",
       "RegioesFilhas": [{
           "Cidade": "Brasília",
           "UF": "DF",
           "ID": "1"
       }, {
           "Cidade": "Asa Sul",
           "UF": "DF",
           "ID": "2"
       }],
       "Cidade": {
           "UF": "DF",
           "Cidade": "Brasília"
       }
   }
  • See if this post helps you: http://stackoverflow.com/questions/21703722/angularjs-ng-repeat-setting-attributes

3 answers

4


You can do it that way:

Instead of using var objeto change to $scope.objeto because this way you will make Binding with the Html in the ng-repeat.

Then just do the binding with the data in the component you want, in this case I used a list.

Recommended reading:

https://docs.angularjs.org/tutorial/step_04

https://docs.angularjs.org/guide/scope


Example:

var myApp = angular.module('myApp', []);

function MyCtrl($scope) {

$scope.objetos = {
       "DescricaoRegiaoVaga": "",
       "IdCidadeCorreios": "1",
       "RegioesFilhas": [{
           "Cidade": "Brasília",
           "UF": "DF",
           "ID": "1"
       }, {
           "Cidade": "Asa Sul",
           "UF": "DF",
           "ID": "2"
       }],
       "Cidade": {
           "UF": "DF",
           "Cidade": "Brasília"
       }
   }

}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp" ng-controller="MyCtrl">
 <ul ng-repeat="objeto in objetos.RegioesFilhas">
  <li>{{objeto.Cidade}}</li>
  <li>{{objeto.UF}}</li>
  <li>{{objeto.ID}}</li>
</ul> 
</div>

1

Hello, try to define how $scope.objeto or instead of var = objeto. Here it spun pretty

0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.