Questions tagged [angularjs-watch]

The AngularJS watch listener may change the model, which may trigger other listeners to fire. This is achieved by rerunning the watchers until no changes are detected.

The AngularJS $watch() is some of the central functions in AngularJS. AngularJS creates a "watch" internally. A watch means that AngularJS watches changes in the variable on the $scope object.

129 questions
457
votes
11 answers

Watch multiple $scope attributes

Is there a way to subscribe to events on multiple objects using $watch E.g. $scope.$watch('item1, item2', function () { });
Greg
  • 31,180
  • 18
  • 65
  • 85
49
votes
4 answers

AngularJS $watch vs $watchCollection: which is better for performance?

For watching an object scope variable, is $scope.$watch with objectEquality set to true OR $scope.$watchCollection better? For a $scope object variable (like 15 attributes, some nested 2 levels deep) updated with input elements and ng-model in the…
user12121234
  • 2,519
  • 2
  • 25
  • 27
12
votes
2 answers

Do I need to "unwatch" scope variables when the scope is being destroyed?

Below are the docs from angular. I'm watching several variables that are part of this scope to build up a filter string for ng-grid. When this scope is being destroyed, do I NEED to unwatch them by calling the return value from $scope.$watch, or…
boatcoder
  • 17,525
  • 18
  • 114
  • 178
11
votes
2 answers

Watch form model for changes

Assuming a given form such as
, it's easy enough to watch for validity, error, dirty state, etc. using a simple watch: $scope.$watch('myForm.$valid', function() { console.log('form is valid? ', $scope.myForm.$valid);…
Duncan
  • 2,550
  • 2
  • 17
  • 18
8
votes
1 answer

Angularjs: why there are 3 watchers for 1 binding?

Please take a look at the screenshot given below As you can see in the screenshot above there are #3 watchers for a single binding. Can anyone please elaborate why is it so? P.S: I am using AngularJS Batarang for checking the performance. var app…
Vikas Bansal
  • 10,662
  • 14
  • 58
  • 100
8
votes
3 answers

What is considered a watcher in Angular?

What are considered "watchers" in Angular? Are watchers themselves the only type of watchers, or are other Angular constructs such as ngModel watchers as well? Or am I missing the big picture? For example, are watchers what enable directives like…
LazerSharks
  • 3,089
  • 4
  • 42
  • 67
8
votes
1 answer

watch factory variable with Angular

My single page application has 2 controllers : the first is for my main menu and the second is for the view. They share data with this factory myApp.factory('MenuFactory', function(){ var factory = { Monitor: "doneJob", Control: "", …
5
votes
0 answers

AngularJS finding who changed an object watched by $watch

I'm using Angular-Bootstrap Carousel directive and making some changes on top of it. The Carousel had ng-repeat for the slides. I'm trying to get to the next/previous slide by hovering the right/left controls instead of by click. And achieving that…
AlexD
  • 4,062
  • 5
  • 38
  • 65
4
votes
1 answer

How does angular binding happen?

Below is my understanding of how binding happens in angularJS. Would be great if experts can provide feedback/comment..
{{myvar}} {{anothervar}}
$scope.watch( function (scope) { return scope.anothervar; …
noi.m
  • 3,070
  • 5
  • 34
  • 57
4
votes
3 answers

Angularjs updates the view but not the model

please pay attention this is the opposite of 99% of the related questions on stackoverflow. Mi problem is: I have a dependent select, when the 'Master' select changes, the 'Slave' view gets updated but NOT it's model. WEIRD. Example code:
Daniel
  • 1,287
  • 12
  • 12
3
votes
1 answer

how can i get information about who change the variable i set in the watch (angular)

example $scope.$watch('data', function(){}); The function starts when data will change but if I want to know what function cause to the change.
david lopez
  • 405
  • 2
  • 5
  • 16
3
votes
3 answers

ng-change doesn't get fired for email input unless I enter a valid email address

Model value for invalid email input is always undefined. I would like to be able to check if the user has entered any text (even if it's not yet a valid email address). Please check plnkr for more details on the implementation:…
simonaco
  • 346
  • 2
  • 4
  • 15
3
votes
1 answer

Bug when value and label of ng-options are equivalent?

I'm experiencing an issue if I set ng-options from within a $scope.$watch statement. The following works: But this doesn't: