My Technical Notes

Monday, 15 June 2015

Angular: Using NgRepeat

Here is the HTML:


<div ng-app="testModule">
    <div ng-controller="listController">
        <div ng-repeat="person in persons">
            <span>{{person.id}}</span><br />
            <span>{{person.forename}}</span><br />
            <span>{{person.surname}}</span><br />
        </div>
    </div>
</div>

Here is the module/controller:


(function () {
    var app = angular.module('testModule', []);

    app.controller('listController', function ($scope) {
        $scope.persons = [
            { id: 10, forename: "John", surname: "Barnes" },
            { id: 27, forename: "Gary", surname: "Lineker" },
            { id: 33, forename: "Zinedine", surname: "Zidane" }
        ];
    });
})();

No comments: