Open everson opened 9 years ago
That must have gotten refactored out accidentally at some point. I'll add it back in soon, but the code you need is in app.js. Just replace the current empty AppController with the following.
app.controller('AppController', function ($scope, $state) {
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
if (angular.isDefined(toState.data.pageTitle)) {
$scope.pageTitle = toState.data.pageTitle;
}
});
});
It just plugs into a router event to get the route data and place it on the scope.
I'm probably going to change it to the following to be consistent with the "controller as" syntax when I put it in the generator...
app.controller('AppController', function ($scope, $state) {
var model = this;
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams){
if (angular.isDefined(toState.data.pageTitle)) {
model.pageTitle = toState.data.pageTitle;
}
});
});
and change index.html to ...
<html ng-app="<%=appName%>" ng-controller="AppController as model">
<head>
<title ng-bind="model.pageTitle"></title>
Thanks! :+1: (I noticed it wasn't working and thought I had modified something that broke it ).
BTW, may I suggest the following changes to the above code to go in accordance with the Angular styleguide?
app.controller('AppController', function ($scope, $state) {
var model = this;
$scope.$on('$stateChangeSuccess', stateChangeSuccess);
function stateChangeSuccess(event, toState, toParams, fromState, fromParams) {
if (angular.isDefined(toState.data.pageTitle)) {
model.pageTitle = toState.data.pageTitle;
}
}
});
Do I need to do something special to make it work? the code generated suggests that each route can set the title, but that does not work as it is. Help here would be appreciated.