search

Home  >  Q&A  >  body text

angular.js - Can json objects use ng-repeat

A jsonobject, I hope to traverse to obtain the key and value. Can I use ng-repeat to obtain it, or other simple methods to achieve the following effect;
The following jsonobject will report an error when using ng-repeat

 
$scope.data =  {'aaa' : '123' , ‘bbb’:'456','ccc':'789'}

<p ng-repeat="m in data">
  key = {{m.key}}
  value = {{m.value}}
</p>
过去多啦不再A梦过去多啦不再A梦2827 days ago581

reply all(2)I'll reply

  • 过去多啦不再A梦

    过去多啦不再A梦2017-05-15 17:07:43

    <p ng-repeat="(key, val) in data">
      key = {{key}}
      value = {{val}}
    </p>

    reply
    0
  • 高洛峰

    高洛峰2017-05-15 17:07:43

    You can refer to angular’s ​​official explanation of ngRepeat:

    Iterating over object properties
    It is possible to get ngRepeat to iterate over the properties of an object using the following syntax:

    <p ng-repeat="(key, value) in myObj"> ... </p>

    reply
    0
  • Cancelreply