Last Updated: February 25, 2016
·
7.73K
· gregbenner

Dynamic Site Page Titles with Angular and UI-Router

Pardon the CoffeeScript but should be able to translate easy enough.
I was looking into having different page titles for each ui-route and didn't find great examples so here you go:

<title ng-bind="$state.current.data.title + ' | Site Name'">Site Name</title>

angular.module('app', [])
  .run(($rootScope, $state) ->
    $rootScope.$on('$stateChangeStart', ->
      $rootScope.$state = $state
    )
  )

angular.module('app')
  .config ($stateProvider) ->
    $stateProvider
    .state('main',
      url: '/',
      templateUrl: 'app/main/main.html'
      controller: 'MainCtrl'
      data:
        title: 'Home'
)

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

Angular apps often share the page with analytics and payment scripts that are not Angular modules. Those scripts execute on the same origin as the framework.

Security insights from Cside