AngularJS - ForEach Accessing previous/next index array, Possible? -
$scope.todos = [ {text:'learn', done:true}, {text:'build', done:false}, {text:'watch', done:false}, {text:'destroy', done:false}, {text:'rebuild', done:false}]; $scope.remaining = function() { var count = 0; angular.foreach($scope.todos, function(todo,i) { todo.text = 'want2learn'; todo.text[i+1] = todo.text; });
is possible foreach function accessing/set previous/next index array value of object, possible?
yes,
$scope.todos[i+1].text = todo.text;
you'll want guard against indexing past end of array though:
if(i < $scope.todos.length - 1) { $scope.todos[i+1].text = todo.text; }
angularjs
No comments:
Post a Comment