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

0 votes
I Want to know how $watch can be implement and can be used in angularjs applications to watch scope variable changes?
Feb 3 in Angular by kartik
• 1,910 points
31 views

1 answer to this question.

0 votes

$watch() function is used to watch the changes of variables in $scope object. 

Generally the $watch() function will create internally in Angularjs to handle variable changes in application.

Let us understand with the following example to understand how to implement $watch().

1. Let us consider the following code, where we have three variables i.e variable 'a' having 2-way data binding,variable 'a' having data binding and variable 'b' have data binding(HTML code).

2.Now, consider the following css code where variable a and b has data binding but variable c doesn't have data binding.

3. However, we know that $watch is a function that keep trace of scope variable being used in data binding.

    Therefore,from the above code the $watch count is 3. (variable a has both data binding and variable b).

4.In order to know the $watch count follow these steps:

    4.1 Go to you google chrome and select more tools.

    4.2 Then select extensions.

    4.3 Search for Angular Watcher and click on add to chrome.

    4.4. Then run the above web page(HTML) on your browser and hit right click and select inspect.

    4.5 On the upper right corner of your screen select watcher option.

            

   4.6 The final output will be.

          

[Note]: The above output i.e 3 is based on my code.

answered Feb 3 by anonymous
• 3,230 points

Related Questions In Angular

0 votes
1 answer
0 votes
1 answer

What is the service that is used to configure the UI-Router and ngRoute in AngularJs?

Routing comes into play whenever you want ...READ MORE

answered 6 days ago in Angular by anonymous
• 3,230 points
12 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
• 3,230 points
20 views
0 votes
1 answer

What is $parse in Angularjs

Before we jump into the topic you ...READ MORE

answered Feb 4 in Angular by Niroj
• 3,230 points
25 views
0 votes
0 answers
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
• 1,910 points
26 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
• 3,230 points

edited Jan 21 by Niroj 29 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
• 3,230 points

edited Jan 21 by Niroj 22 views
0 votes
1 answer
0 votes
1 answer