This is pretty easy way to set title for per ui-router state in AngularJS. You can set dynamic title to per ui-router state with this codes in AngularJS.

<head>
  <title ng-bind="$state.current.title + 'Sitename'"></title>
</head>
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
  $urlRouterProvider.otherwise('home');
  $stateProvider
    .state('home', {
      url: '/home',
      templateUrl: 'view/home.html',
      title: 'HomePage - '
    })
    .state('login', {
      url: '/login',
      templateUrl: 'view/login.html',
      title: 'Login - '
    });
}]);

app.run(['$rootScope', '$state', '$stateParams',
  function ($rootScope,   $state,   $stateParams) {
      $rootScope.$state = $state;
      $rootScope.$stateParams = $stateParams;
  }]);

Bir Cevap Yazın

*