fix(view): digest view scope before transition

This commit is contained in:
Adam Bradley
2014-11-30 21:36:45 -06:00
parent 083ae7b54c
commit 8640924b44

View File

@@ -4,14 +4,16 @@ IonicModule
'$element',
'$attrs',
'$compile',
'$rootScope',
'$ionicViewSwitcher',
function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
function($scope, $element, $attrs, $compile, $rootScope, $ionicViewSwitcher) {
var self = this;
var navElementHtml = {};
var navViewCtrl;
var navBarDelegateHandle;
var hasViewHeaderBar;
var deregisters = [];
var viewTitle;
var deregIonNavBarInit = $scope.$on('ionNavBar.init', function(ev, delegateHandle){
// this view has its own ion-nav-bar, remember the navBarDelegateHandle for this view
@@ -41,7 +43,8 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
if (transData && !transData.viewNotified) {
transData.viewNotified = true;
var viewTitle = isDefined($attrs.viewTitle) ? $attrs.viewTitle : $attrs.title;
if (!$rootScope.$$phase) $scope.$digest();
viewTitle = isDefined($attrs.viewTitle) ? $attrs.viewTitle : $attrs.title;
var buttons = {};
for (var n in navElementHtml) {
@@ -73,9 +76,8 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
// but also deregister the observe before it leaves
var viewTitleAttr = isDefined($attrs.viewTitle) && 'viewTitle' || isDefined($attrs.title) && 'title';
if (viewTitleAttr) {
deregisters.push($attrs.$observe(viewTitleAttr, function(val) {
navViewCtrl.title(val);
}));
titleUpdate($attrs[viewTitleAttr]);
deregisters.push($attrs.$observe(viewTitleAttr, titleUpdate));
}
if (isDefined($attrs.hideBackButton)) {
@@ -92,6 +94,14 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) {
}
function titleUpdate(newTitle) {
if (isDefined(newTitle) && newTitle !== viewTitle) {
viewTitle = newTitle;
navViewCtrl.title(viewTitle);
}
}
function deregisterFns() {
// remove all existing $attrs.$observe's
for (var x = 0; x < deregisters.length; x++) {