Using $scope.$watch() for observing changes
AngularJS provides the $scope.$watch() function to observe changes in scope variables and execute a callback whenever the watched value changes. This is useful for reactive programming where you want to….