From 8b44004af21aef8d80351c1034c517645b2029fa Mon Sep 17 00:00:00 2001 From: UniRing Date: Fri, 31 Jan 2014 00:59:12 +0100 Subject: [PATCH] Allows a view to update the navbar title if his title changes Added a watch to see if the contents of the view title changes and, if so, fire an event to notify the navbar and update the title. --- js/ext/angular/src/directive/ionicViewState.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/js/ext/angular/src/directive/ionicViewState.js b/js/ext/angular/src/directive/ionicViewState.js index 591310d849..f2ea4d92d8 100644 --- a/js/ext/angular/src/directive/ionicViewState.js +++ b/js/ext/angular/src/directive/ionicViewState.js @@ -137,6 +137,10 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu updateHeaderData(data); }); + $rootScope.$on('viewState.titleUpdated', function(e, data) { + $scope.currentTitle = (data && data.title ? data.title : ''); + }); + // If a nav page changes the left or right buttons, update our scope vars $scope.$parent.$on('viewState.leftButtonsChanged', function(e, data) { $scope.leftButtons = data; @@ -198,10 +202,16 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu $scope.$emit('viewState.rightButtonsChanged', $scope.rightButtons); }); + // watch for changes in the title + var deregTitle = $scope.$watch('title', function(val) { + $scope.$emit('viewState.titleUpdated', $scope); + }); + $scope.$on('$destroy', function(){ // deregister on destroy deregLeftButtons(); deregRightButtons(); + deregTitle(); }); };