What is the difference between $watch and $observe in AngularJS ? Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report AngularJS provides different methods to observe/watch the changes in its elements and variables. The $observe and $watch are two different methods that serve this purpose. $observe is a method that is responsible to observe/watch the changes in the DOM attribute. We use $observe when we want to observe a DOM element that contains interpolation ({{}}). Syntax: <!-- Interpolation Element --> attr1 = "Name: {{name}}" <!-- Syntax of Observe in controller --> attrs.$observe('attr1', function() { // body });Example 1: Here when we click on the hyperlink(switch newest), the attribute gets true or false on the basis of the click event. The $observe is observing the changes in its DOM and putting the attribute values accordingly. HTML <!DOCTYPE html> <html ng-app="AngularObserveExample"> <head> <title> What is the difference between $watch and $observe in AngularJS ? </title> <script src= "http://code.angularjs.org/1.0.6/angular.min.js"> </script> <script> var myApp = angular.module('observeApplication', []); myApp.directive('focus', function () { return function (scope, element, attrs) { attrs.$observe('focus', function (newValue) { newValue === 'true' && element[0].focus(); }); } }); function MyCtrl($scope) { $scope.cues = [{ text: 'text for the first item', isNew: false }, { text: 'text for the second item', isNew: true }]; $scope.switchNewest = function () { $scope.cues[1].isNew = !$scope.cues[1].isNew $scope.cues[0].isNew = !$scope.cues[0].isNew } } </script> </head> <body> <div ng-app="observeApplication" ng-controller="MyCtrl"> <ul> <li ng-repeat="cue in cues" class="form-inline"> <input type="text" ng-model="cues[$index].text" focus="{{cue.isNew}}" class="input-xlarge" /> {{cue.isNew}}</li> </ul> <a ng-click="switchNewest()">switch newest</a> </div> </body> </html> Output: $watch: To observe any expression, either function or a string we use a $watch method. It is a method on the $scope object, therefore, it can be used wherever you have access to a scope object (including any controller or linking functions in the directive). When we want to observe/watch any model/scope property we use $watch. Syntax: attr1 = "myModel.some_prop"; scope.$watch(attrs['attr1'], function() { // body });Example 2: In this example, we are putting the text in the text field and as the cursor is up or down the function is called the changes are observed by $watch and we are displaying the count of the number of times a function is called. HTML <!DOCTYPE html> <html> <head> <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"> </script> <script type="text/javascript"> var app = angular.module('watchApplication', []); app.controller('watchCtrllr', function ($scope) { $scope.countCheck = -1; $scope.$watch('textval', function (newval, oldval) { $scope.countCheck = $scope.countCheck + 1; }); }); </script> </head> <body> <div ng-app="watchApplication" ng-controller="watchCtrllr"> <h2>AngularJS $watch() Function Example</h2> Enter Text:<input type="text" ng-model="textval" /> <br /><br /> <span style="color:Red"> No. of Times $watch() Function Fired: {{countCheck}} </span> </div> </body> </html> Output: Difference Between $observe and $watch: $watch$observeObserve changes in string/expression/function. Observe changes in the DOM element. $watch is a way of triggering changes in the digest. $observe watches changes in interpolation ({{}}) elements. $watch uses $scope to watch changes in its values. $observe is used in the linking function of directives. Comment More infoAdvertise with us Next Article What is the difference between $watch and $observe in AngularJS ? P pganesh Follow Improve Article Tags : Web Technologies AngularJS AngularJS-Questions Similar Reads What is the Difference Between factory and service in AngularJS ? AngularJS is a JavaScript-based framework. It can be used by adding it to an HTML page using a <script> tag. AngularJS helps in extending the HTML attributes with the help of directives and binding of data to the HTML with expressions. In this article, we will explore the differences between t 4 min read What is the Difference Between Promises and Observables in Angular ? Angular is a TypeScript-based Single-Page Application framework used to create dynamic and responsive web applications. It is one of the most popular and robust frameworks. One of its key features is to handle Asynchronous Operations effectively. In Asynchronous, code is not executed sequentially ra 5 min read What is the Difference Between BehaviorSubject and Observable in Angular ? Angular being a powerful framework offers various features and tools. One such powerful feature is to handle asynchronous operations by implementing the BehaviorSubject and Observable, which are the key components of the RxJS library. It also helps to manage the flow of data reactively. This article 5 min read What is the Difference Between $routeProvider and $stateProvider in AngularJS ? In AngularJS, as we create Single-Page Applications, we need to implement the routing of components to view those images without having full page reloads. This can be achieved with the most popular routing methods, i.e., $routeProvider (ngRoute) and $stateProvider (ui-router).In this article, we wil 5 min read What is the difference between '@' and '=' in directive scope in AngularJS ? AngularJS is a popular JavaScript framework, that provides powerful features for building dynamic web applications. When creating custom directives in AngularJS, you may come across the need to define a scope for your directive. The two most common methods to do this are by using the @ and = symbols 4 min read What is the difference between Service Directive and Module in Angular ? Angular is a Typescript framework used to build dynamic and Single-Page Applications. This has a strong focus on modularity and reusability of code which helps in creating complex and maintainable applications. At the core, Angular has 3 fundamental building blocks, i.e., Service, Directive and Modu 6 min read What is the Difference Between $evalAsync and $timeout in AngularJS? AngularJS is a JavaScript framework, which may be utilized by including it in an HTML web page the usage of a <script> tag. AngularJS enables in extension the HTML attributes with the assistance of directives and binding of data to the HTML with expressions. It provides various tools for handl 5 min read What is the difference between change and ngModelChange in Angular? change: The change event is fired for <input>, <select>, and <textarea> elements when an alteration to the element's value is committed by the user.The change event is not necessarily fired for each alteration to an element's value. change is a DOM event that is it can trigger chan 2 min read What's the difference between ng-pristine and ng-dirty in AngularJS ? AngularJS supports client-side form validation. AngularJS keeps track of all the form and input fields and it also stores the information about whether anyone has touched or modified the field or not. The two different classes ng-dirty and ng-pristine that are used for form validation, are described 2 min read What is the difference between ng-app and data-ng-app in AngularJS ? In web application development, AngularJS is one of the most favorite dynamic JavaScript frameworks that has HTML through script tags, enabling us to augment the HTML attributes using the directives and facilitating the data binding through the expressions.In this article, we will see the concepts o 5 min read Like