Angularjs

Set Page Title In AngularJS

Posted by Weston Ganger on July 19, 2015

I usually like to set page titles on my angular templates.


var myApp = angular.module('myApp', ['ngResource']);

myApp.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/', {
    title: 'Home',
    templateUrl: '/assets/views/home.html',
    controller: 'HomeController'
  });
  $routeProvider.when('/Product/:id', {
    title: 'Product',
    templateUrl: '/assets/views/product.html',
    controller: 'ProductController'
  });
}]);

myApp.run(['$location', '$rootScope', function($location, $rootScope) {
  $rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
    $rootScope.title = current.$$route.title;
  });
}]);


Related External Links:


Posted in Angular and Tagged with angularjs 


Need help on your next project or application?

I specialize in Ruby-on-Rails, AngularJS, Javascript, Bootstrap, and Hybrid Mobile Apps with Cordova & Ionic.

Contact Me

Recommended Posts