4

I have the following ng-repeat code:

<li ng-repeat="vid in vids | filter:query | orderBy:orderProp">
       {{vid.title}}
</li>

My question is, can I loop through vids and print out each and every key and value if I don't know the key name?

So sort of how I would do it in php:

<?php
foreach ($vids as $key => $val) {
    echo $key . "=" . $val;
}
?>
2
  • 1
    vid = $val, $index = $key... docs.angularjs.org/api/ng.directive:ngRepeat Commented May 23, 2013 at 13:08
  • My previous comment is wrong in the context of objects. I expected an array because of =>. +1 for a good question and +1 for Ajay for a good answer. Commented May 23, 2013 at 15:25

1 Answer 1

5

I am totally not sure about question but it should work

<!DOCTYPE html>
<html ng-app="myApp" >
<head>
    <title></title>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.min.js"></script>
</head>
<body  ng-controller="testctrl">
    <div ng-repeat="vid in vids">
        <span ng-repeat ="(key, value) in vid">{{key}} ,{{value}}</span>
    </div>
  <script>
      var app = angular.module('myApp', []);
      app.controller('testctrl', function ($scope) {
          $scope.vids = [{ 'adam': 10, 'amalie': 12 }, { 'adam': 12, 'amalie': 12 }];
      });
  </script>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.