Chapter 3 ■ IntroduCtIon to MVC
The output, as shown in Figure 3-2, is simply a count of the number of employees, courtesy of the Array.length
property.
Perhaps the most important aspect of Listing 3-3 is how we use a scope object, an instance of which, as we
discussed, was passed into our controller function by the framework. It really is quite fundamental to how AngularJS
does much of its work. We can already see it being used to decouple the model from the view, but it actually does
something a little bit more impressive than keep our code clean and modular. It is also a key player in the framework’s
ability to keep the model and the view in sync with each other. The changes made to the model were immediately
reflected in the view; we did not have to do any Document Object Model (DOM) manipulation.
■ Tip If you have been working with jQuery for a while, you might find the lack of doM manipulation a bit peculiar at
first. jQuery is all about doM manipulation, and you might have to make an effort to shake off that way of thinking when
you are working with angularJS.
We are nearly at the end of this chapter, but before moving on, I want to show you one more code sample.
Listing 3-4 demonstrates another AngularJS approach toward code organization, to keep things clean and crisp.
Listing 3-4. Displaying the Employee Names
<!DOCTYPE html>
Figure 3-2. Counting the number of employees (output of Listing 3-3)