2

I want to fire an event when my multidimensional scope variable get changed i.e. element added, removed etc. I tried to do so using $scope.$watch and $scope.$watchCollection, but its not working.

This is the scenario.

$scope.variable=[{ID:1,text:'abc'},{ID:1,text:'abc'}];
$scope.content='';

$scope.$watch('$scope.variable',function(){
$scope.content=$scope.variable[0].text;
});

Any help ?

1 Answer 1

2

add true as an argument

$scope.$watch('variable',function(){
   $scope.content=$scope.variable[0].text;
}, true);

NB: no need for $scope in argument

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

Comments

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.