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, 2020 in Angular by kartik
• 37,520 points
2,482 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.

Hope it helps!!

To know more about Angular, Join best Angular certification course today.

Thank you!!

answered Feb 3, 2020 by anonymous
• 82,840 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 Feb 11, 2020 in Angular by anonymous
• 82,840 points
555 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, 2020 in Angular by Niroj
• 82,840 points
1,302 views
0 votes
1 answer

What is $parse in Angularjs

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

answered Feb 4, 2020 in Angular by Niroj
• 82,840 points
2,535 views
0 votes
1 answer
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, 2020 in Web Development by anonymous
• 37,520 points
935 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, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 1,144 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, 2020 in Web Development by Niroj
• 82,840 points

edited Jan 21, 2020 by Niroj 906 views
0 votes
1 answer
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP