ng-repeat example

Two variants of ng-repeat

by digitalzebra

HTML

<div ng-app="foobar">
    <div ng-controller="lol">
        <b>First list:</b>
    <div ng-repeat="item in items">
        {{item}}
    </div>
        <b>Second list:</b>
            <div ng-repeat="item in getItems()">
        {{item}}
    </div>
        <button ng-click="doStuff()">Click me</button>
        <button ng-click="doOtherStuff()">Do Other stuff</button>
    </div>
</div>

JavaScript

angular.module("foobar", []).controller("lol", function($scope) {
   $scope.items = ["loe", "le", "effe"];
    var blah = ["leoele", "elelkej", "elfkjflkje"];
    
    $scope.doStuff = function() {
      $scope.items.push("eee", "eeelkjf");  
    };
    
    $scope.getItems = function() {
        return blah;
    }
    
    $scope.doOtherStuff = function() {
      blah.push("elejlee'e");  
    };
});