The largest Interview Solution Library on the web


« Previous | 1 | 2 | 3 | Next »
AngularJS supports Single Page Application via multiple views on a single page. To do this AngularJS has provided ng-view and ng-template directives and $routeProvider services.

ng-view
ng-view tag simply creates a place holder where a corresponding view (html or ng-template view) can be placed based on the configuration.

Usage
Define a div with ng-view within the main module.
<div ng-app = "mainApp">
...
<div ng-view></div>
</div>
ng-template
ng-template directive is used to create an html view using script tag. It contains "id" attribute which is used by $routeProvider to map a view with a controller.
Define a script block with type as ng-template within the main module.
<div ng-app = "mainApp">
...... <script type = "text/ng-template" id = "addEmp.htm">
<h2> Add An Employee </h2>
{{message}}
</script>
</div>
$routeProvider
$routeProvider is the key service which set the configuration of urls, map them with the corresponding html page or ng-template, and attach a controller with the same.
Define a script block with type as ng-template within the main module.
<div ng-app = "mainApp">
... <script type = "text/ng-template" id = "addEmp.htm">
<h2> Add An Employee </h2>
{{message}}
</script>
</div>
Define a script block with type as ng-template within the main module.
<div ng-app = "mainApp">
<script type = "text/ng-template" id = "addEmp.htm">
<h2> Add An Employee</h2>
{{message}}
</script></div>
Define a script block with main module and set the routing configuration.
var mainApp = angular.module("mainApp", ['ngRoute']);
mainApp.config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/addEmp', {
templateUrl: 'addEmp.htm', controller: 'AddEmpController'
}).
when('/viewEmp', {
templateUrl: 'viewEmp.htm', controller: 'ViewEmpController'
}).
otherwise({
redirectTo: '/addEmp'
});
}]);
« Previous | 1 | 2 | 3 | Next »


copyright © 2014 - all rights riserved by javatechnologycenter.com