Andres Andres - 12 days ago 7
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:
https://jsfiddle.net/purple_lightsaber/edegcLnh/

PS:

ng-click="changeAllValues()


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

Any help is appreciated :)

Answer

You can do this,

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

DEMO