What are the type of $watch()?

0 votes
Can someone help me with the general syntax of $watch() types and explain it??
Feb 3 in Angular by kartik
• 26,940 points
79 views

1 answer to this question.

0 votes

hey kartik,

Before you move in to the topic do check- $watch and watch listener function first.

$watch() function is used to watch the changes of variables in $scope object and watch listener is a function that is executed automatically when variable changes its value at its scope.

Generally,there are four types of $watch(). They are:-

1.) $watch-reference watch:

"o" is a object has the property contain in it. For object "o" watch listener function is created and the event will fire only if object "o" will assign to other object.

[Note]: No changes will occur if object's "o" property is modify. 

2.) $watch with "true"- Equality watch:

    Equality watch is same as Reference watch but the only difference is that if you provide "true" value in watch listener function at the end it will allow event to be fire even object "o" property is chnaged.

3:) $watch group:

watch group function is used to manipulate watch scope of the variable that is not binded to no scope. Simply we can use array of several other scope variable

4:)Collection watch:

It is used to watch array. It can also be used to detect modification to an array (i.e adding or deleting). However to achieve this use Equality watch.

here scope emp contains data, However if we add items to it then watch function event will fire automatically if we push data to emp array 

{Note}: It will not execute if any modification of arrays data will occur.(executed only if any add or deletion will take place in an array).

answered Feb 3 by Niroj
• 58,100 points

Related Questions In Angular

0 votes
1 answer

What are the $route service Events provide in AngularJs?

hey, $route is used for deep-linking URLs to controllers ...READ MORE

answered Feb 10 in Angular by Niroj
• 58,100 points
83 views
0 votes
1 answer

What is the top advantages of using UI-router over ngRoute?

Hey, In Client side Routing there are several ...READ MORE

answered Feb 11 in Angular by anonymous
• 58,100 points
135 views
0 votes
1 answer

What are the features supported in UI-Router Parameters?

UI-Route describes how the UI looks like ...READ MORE

answered Feb 11 in Angular by Niroj
• 58,100 points
68 views
0 votes
1 answer

What is $watch() and it's use in AngularJS?

$watch() function is used to watch the ...READ MORE

answered Feb 3 in Angular by anonymous
• 58,100 points
122 views
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17 in Web Development by anonymous
• 26,940 points
84 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20 in Web Development by Niroj
• 58,100 points

edited Jan 21 by Niroj 122 views
+1 vote
1 answer

What are pseudo class in css??

Hey, The state of an element is controlled  by ...READ MORE

answered Jan 20 in Web Development by Niroj
• 58,100 points

edited Jan 21 by Niroj 70 views
0 votes
1 answer

What is the use of $eval in alert()?

Hey, kartik!! There is not much difference in ...READ MORE

answered Feb 4 in Angular by Niroj
• 58,100 points
107 views
0 votes
1 answer

What are the steps involved in ng-route in AngularJS?

Hello, As Routing is just another way of fixing some content ...READ MORE

answered Feb 6 in Angular by Niroj
• 58,100 points
80 views