In this video Iftach Bar shows another possible usage of the $watch function, watching a function instead of an expression.
- [Instructor] There is another way to use…the dollar watch first argument.…The thing we watch can be a string with an expression…like we've seen before, like we've watched vm.force.…Or it can be a function that returns value.…When we use a function that returns a value…the return value will be the value that is watched.…So for example if we want to watch if the force is even…or odd, I'll just write a new function that returns…vm.force modular two equals equals zero.…
And now the new value and the old value arguments…are going to be true or false, depends on what this…function returns.…I am going to change my console log statement to reflect…whether the force is even or odd.…If the new value is true, it means the force is even.…And if it's false, it means the force is odd.…Let's go back to the app and see what happens.…Whenever I change the value, for example I'm going to…add the one here then we're going to see a listener…code and the force is going to be odd.…
If I'm going to add another one here the force is…
This advanced AngularJS course helps you explore the connected worlds of $scope and the digest cycle. Instructor Iftach Bar explains scope and inheritance, goes behind the scenes of the digest loop, and teaches both manual and automatic data binding approaches. Plus, learn how to integrate external libraries, diagnose performance issues, and debug your applications.
- $scope and controllers
- $scope built-in variables and methods
- $scope prototype inheritance
- Manual data binding with $scope.$watch
- The digest loop
- Get the $scope in the console
- Forcing $digest
Skill Level Advanced
AngularJS 1: Building a Data-Driven Appwith Ray Villalobos2h 15m Intermediate
1. Scope Basics
2. Manual Data Bindings
3. The Digest Loop
4. Tips for Debugging Angular in the Console
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.