1
<textarea ng-model="statement" name="statement"></textarea>

when i typing some values in text area i can trigger a function in cotroller by using

var autosave = function(newVal, oldVa){
    console.log('inside the function');
}
$scope.$watch('statement', autosave);

here i want to check the value array contain some value, if the values exist i want to trigger some function in controller

$scope.testAry =[];

i am going to push some values

$scope.testAry.push({username: jenson});

This time the array contain the values so i need to trigger a function

   $scope.$watch('testAry', autosave); // not working 

can anyone help me to trigger the autosave function if the array contain at least one value

1 Answer 1

1

Pass third parameter true to watch array values:

$scope.$watch('testAry', autosave, true);

Or you may use $watchCollection.

Sign up to request clarification or add additional context in comments.

1 Comment

thank you Bhojendra Nepal, $watchCollection is working for me, $scope.$watchCollection('testAry', autosave);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.