I'm trying to figure out why a script I'm using is giving an error. I have two pages on my application and I would like some header text to change when the view is switched. It works in its current form, but I keep getting a console error which I'd like to fix. Here is the code:
.run(['$rootScope', function($rootScope) {
$rootScope.$on('$routeChangeSuccess', function (event, current, previous) {
$rootScope.title = current.$$route.title;
});
And then in my HTML:
<h1 class="section-intro" ng-bind="title"></h1>
But I keep getting this error:
TypeError: Cannot read property 'title' of undefined
at app.js:39
at Scope.$broadcast (angular.js:16165)
at angular-route.js:619
at processQueue (angular.js:14567)
at angular.js:14583
at Scope.$eval (angular.js:15846)
at Scope.$digest (angular.js:15657)
at Scope.$apply (angular.js:15951)
at HTMLBodyElement.<anonymous> (angular.js:12086)
at HTMLBodyElement.jQuery.event.dispatch (jquery.js:4435)
Which has something to do with:
$rootScope.title = current.$$route.title;
I'm mostly confused because the script works, but the error is being thrown when I switched back and fourth.
$root.titlenot justtitle. Also, double$$between current and route?$$is reserved for private variables.