Andres Andres - 1 year ago 66
AngularJS Question

Change property for every value in ng-repeat

You can see in my fiddle that the value for each name is set to 0.

I'd like my changeAllValues() to change all the

value: 0's

to be

value: 1's!

What is the best way to do this?

JS Fiddle:



must be outside of my ng-repeat like it is in the fiddle.

Any help is appreciated :)

Answer Source

You can do this,

 $scope.changeAllValues = function() {
      angular.forEach($scope.names, function(item) {
        item["value"] = 1;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download