Angular Js - Example - List Item using ng-repeat

Angular Js - Example Directive: ng-repeat Repeat the json data

by Steve Ayers

HTML

<div ng-app>
    <b>First List</b>
    <ul ng-controller="MainCtrl">
        <li ng-controller="FirstCtrl" ng-click="popup()" ng-repeat="item in items">
            {{item}}
        </li>
    </ul>
    <b>Second List</b>
    <ul ng-controller="MainCtrl" >
        <li ng-controller="SecondCtrl as wakka" ng-click="wakka.popup()" ng-repeat="item in items">
            {{item}}
        </li>
    </ul>
</div>

JavaScript

var m = [1,2,3,4];

function MainCtrl($scope) {
    $scope.items = m;
}

function FirstCtrl($scope) {
    var popup = function(variable) {
        alert($scope.item);
    };
    $scope.popup = popup;
}

function SecondCtrl($scope) {
    var popup = function(variable) {
        alert($scope.item);
    };
    this.popup = popup;
}