Vote count:
0
Assuming the following scenario: first click cont! button and then add!, How to apply in counting function newly pushed object in array, so that it would be displayed as last in ng-repeat?
var app = angular.module('app', []);
app.controller('homeCtrl', function($scope, $interval) {
$scope.tabs = [{
name: "one",
active: true
}, {
name: "two",
active: false
}, {
name: "three",
active: false
}];
$scope.add = function() {
$scope.tabs.push({
name: "display me in the counter",
active: false
});
};
$scope.count = function() {
var i = 0;
var interval;
$interval.cancel(interval);
interval = $interval(function() {
$scope.tabs[i].active = false;
i++
$scope.tabs[i].active = true;
i = i % $scope.tabs.length;
}, 2000, $scope.tabs.length - 1, true);
}
});
<script src="http://ift.tt/1mQ03rn"></script>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<div ng-app="app">
<div ng-controller="homeCtrl">
{{tabs}}
<br>
<button ng-click="add()" class="btn btn-default">add!</button>
<button ng-click="count()" class="btn btn-default">count!</button>
<div ng-repeat="no in tabs" ng-show="no.active" ng-bind="no.name">
</div>
</div>
</div>
asked 1 min ago
How to apply newly added object in array in ng-repeat interval?
Aucun commentaire:
Enregistrer un commentaire