Using a controller
The web page is our view in the MVC pattern. The controller object is responsible for showing data from the model (binding them to DOM elements in the view) and in response to events, possibly changing model data and displaying these changes in the view. All public fields of the controller can be shown, and all public methods can be invoked from within the view. Data binding is done through the same syntax as in Polymer using double curly braces {{ … }}
. A controller should contain only the business logic needed for a single app or view; it should not manipulate the DOM.
In this recipe, we'll show you how to work with an Angular controller step by step. You can follow along with the code in the project angular_controller
.
How to do it...
Our app will show job type data in a list, and when a job is selected, its details are shown, as shown in the following screenshot:
Its working is explained as follows:
- The
Job
class, which is the model...