user11
user11

Reputation: 39

How to change pageTitle dynamically on state change angularjs inside state routing

I want to change the pageTitle inside data in state Provider.

$stateProvider.state(test, {
  url: '/test',
  views: {
    main: {
      controller: 'TestCtrl',
      templateUrl: 'admin/test.tpl.html'
    }
  },
  data: {
    pageTitle: 'Need some dynamic title',                        
  },                    
});

Here I want to set the page title dynamically may be somewhere inside $state.go().

I tried using

//The controller from where the state is called and we got to know what the title is
$state.get('test').data.pageTitle = $scope.title;
$state.go('test');  

But nothing has happened. Please help.

Upvotes: 2

Views: 376

Answers (1)

P.S.
P.S.

Reputation: 16384

Inside $state.go() you can do:

$state.go('test', {pageTitle: $scope.title});

(or it will be data.pageTitle: $scope.title, I'm not absolutely sure).

And you didn't include any HTML, so don't forget to bind value to title tag like this:

<title ng-bind="$state.current.data.pageTitle"></title>

Upvotes: 2

Related Questions