formations/javascript/angular/directives-3.md

656 B

.cadoles-slide-title[Les directives de base (3/)]

Itération avec ng-repeat: sur un objet

<html>
  <body ng-app="myApp">
    <div ng-controller="MainCtrl">
      <ul>
        <li ng-repeat="(key, val) in myObj">
          <span>Clé: {{ key }}</span><span>Valeur: {{ value }}</span>
        </li>
      </ul>
    </div>
    <script src="angular.js"></script>
    <script>
      angular.module('myApp', [])
        .controller('MainCtrl', ['$scope', function($scope) {

          $scope.myObj = [
            'prop1': 'Foo',
            'prop2': 'Bar'
            'prop3': 'Baz'
          ];

        }]);
    </script>
  </body>
</html>