AngularJS show 2 random records -
AngularJS show 2 random records -
i started learning angularjs , have no thought how solve problem. illustration have 4 records (car, plane, ship, train) , want show 2 randomly in ng-repeat.
examples: 1.st. plane, ship 2.nd. car, train 3.rd. train, plane
so how syntax ?
js:
app.controller('workctrl', function($scope, $http) { $http.get('work.json').success(function(work) { $scope.work = work; }); }); html:
<div class="work" ng-controller="workctrl"> <ul class="grid"> <li ng-repeat="work in work"> <a href="@{{ work.link }}" target="blank_"> <div class="background"></div> <h3 class="name">@{{ work.name }}</h3> <p class="description">@{{ work.description }}</p> <img ng-src="@{{ work.image_path }}"> </a> </li> </ul> </div> <div ng-repeat="w in work = (work|orderby:randomize).slice(0, 2)"> $scope.randomize = function () { homecoming 0.5 - math.random(); };
demo: http://jsfiddle.net/hmx2zqex/
angularjs
Comments
Post a Comment