Last active
August 29, 2015 14:12
-
-
Save imjoshholloway/7df1282e2dfe99a186dd to your computer and use it in GitHub Desktop.
Angular Page Title Directive (http://plnkr.co/edit/buNRB4v1hOt7tQt7NAeX?p=preview)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(angular, undefined) { | |
'use strict'; | |
angular.module('app', ['title', 'ui.router']) | |
.config(appConfig); | |
function appConfig($stateProvider) { | |
$stateProvider.state('app.dashboard', { | |
url: '/', | |
settings: { | |
pageTitle: 'Dashboard', | |
} | |
}); | |
} | |
})(angular); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(angular, undefined) { | |
'use strict'; | |
angular.module('title') | |
.controller('TitleController', TitleController); | |
function TitleController($scope) { | |
var vm = this; | |
vm.pageTitle = ''; | |
$scope.$on('$stateChangeSuccess', updatePageTitle); | |
////////// | |
function updatePageTitle(event, toState) { | |
if (toState) { | |
if (toState.settings && toState.settings.pageTitle.trim() !== '') { | |
vm.pageTitle = toState.settings.pageTitle.trim() + ' | App'; | |
return true; | |
} | |
} | |
return 'App'; | |
} | |
} | |
})(angular); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(angular, undefined) { | |
'use strict'; | |
angular.module('title', []).directive('title', TitleDirective); | |
function TitleDirective() { | |
return { | |
restrict: 'E', | |
controller: 'TitleController', | |
scope: { | |
name: '=' | |
}, | |
controllerAs: 'title', | |
bindToController: true, | |
template: '{{title.pageTitle}}' | |
} | |
} | |
})(angular); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment