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 


Want me to help develop your next project or application?

Contact Us

Specializing in Ruby-on-Rails, Javascript, Multi-Platform Electron Desktop Apps and Hybrid Cordova Mobile Apps.

Recommended Posts