Learning AngularJS Part 4/4

Word Reverser - Using $watch

Posted on August 18, 2015 in angularseries, webdev
Note this is part of the "Learning AngularJS Series".
See a list of these projects here

Using $watch

I believe the beauty of MVC architecture is in the constant communication between the model, view, and controller. It was pleasing to see how easily the view renews itself with “$watch”. In the past I have used multiple javascript functions to update the DOM based on user input. “$watch” succinctly does all that for you.

I thought an easy way to implement this would be to create a live word-reverser. As you type the word, $watch updates the view to reverse the order of the letters you type.

Not much goes on in the html, other than basic value binding. Here is the javascript, which is very simple:

See it on Github

comments powered by Disqus