Categories: Angular || Angular JS ||
AngularJS Templates, Views, Models, Controllers
AngularJS partials, also called templates, are code sections that contain HTML code that are bound to the <div ng-view></div></div> tag shown in the index.html file earlier in this chapter. If you look back at the complete app.js file, you can see that different templateUrl values are defined for each route.
The main.html and show.html files listed next show the two defined partials (templates).
The templates contain just HTML code, with nothing special at this time. Later, we will use AngularJS’s built-in template language to display dynamic data in our templates:
<!-- chapter1/main.html -->
<!-- chapter1/show.html -->
<div>Show The World</div>
As the user clicks on the different links, the value assigned to <div ng-view> is replaced with the content of the associated template files. The value of controller defined for each route references the controller component (of the MVC pattern) that is defined for each particular route.
That often helps developers familiar with design patterns to quickly grasp AngularJS concepts.
AngularJS Views (MVC)
Building views in AngularJS is a simple process that uses mostly HTML and CSS. The simplicity of ngularJS views is a huge time-saver when you’re building AngularJS applications.
AngularJS Models (MVC)
AngularJS Controllers (MVC)
AngularJS controllers are the tape that holds the models and views together. The controller is where you should place all business logic specific to a particular view when it’s not possible to place the logic inside a REST service. Business logic should almost always be placed in backend REST services whenever possible; this helps to simplify AngularJS applications.
When business logic placed inside an application is used by multiple controllers, it should be placed in AngularJS non-REST services instead. Those services can then be injected into any controller that needs access to the logic.