Marc Rasmussen
Marc Rasmussen

Reputation: 20555

angularjs $watch get index of changed array item

i have an array that consists of multiple objects.

    $scope.userCompetences = [];

Now i have a deep watch on this array to check for changes:

    $scope.$watch('userCompetences', function (newVal, oldValue) {
    if(oldValue.length > 0)
    {
        var i = 0; // do something
    }
}, true);

Now my question is how can i get the index of the object in the array that has changed ?

Upvotes: 1

Views: 1975

Answers (1)

ohboy21
ohboy21

Reputation: 4319

Did you try to just call a function when this happens?

<div ng-repeat="item in userCompetences">
   <input type="text" ng-model="item.name" ng-change="change_function($index)"/>
</div>

Upvotes: 3

Related Questions