Skip to content

Commit

Permalink
Fixed #254
Browse files Browse the repository at this point in the history
  • Loading branch information
mlynch committed Dec 4, 2013
1 parent 4c0e82e commit a83b573
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
12 changes: 11 additions & 1 deletion dist/js/ionic-angular.js
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,13 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
}
});

// If a nav page changes the left or right buttons, update our scope vars
$scope.$parent.$on('navRouter.leftButtonsChanged', function(e, data) {
$scope.leftButtons = data;
});
$scope.$parent.$on('navRouter.rightButtonsChanged', function(e, data) {
$scope.rightButtons = data;
});

/*
$scope.$parent.$on('navigation.push', function() {
Expand Down Expand Up @@ -1361,14 +1368,17 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
$scope.$watch(leftButtonsGet, function(value) {
$scope.leftButtons = value;
if($scope.doesUpdateNavRouter) {
$scope.$emit('navRouter.leftButtonsChanged', $scope.rightButtons);
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
}
});

// watch for changes in the right buttons
var rightButtonsGet = $parse($attr.rightButtons);
$scope.$watch(rightButtonsGet, function(value) {
$scope.rightButtons = value;
if($scope.doesUpdateNavRouter) {
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
}
});

// watch for changes in the title
Expand Down
12 changes: 11 additions & 1 deletion js/ext/angular/src/directive/ionicNavRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,13 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
}
});

// If a nav page changes the left or right buttons, update our scope vars
$scope.$parent.$on('navRouter.leftButtonsChanged', function(e, data) {
$scope.leftButtons = data;
});
$scope.$parent.$on('navRouter.rightButtonsChanged', function(e, data) {
$scope.rightButtons = data;
});

/*
$scope.$parent.$on('navigation.push', function() {
Expand Down Expand Up @@ -333,14 +340,17 @@ angular.module('ionic.ui.navRouter', ['ionic.service.gesture'])
$scope.$watch(leftButtonsGet, function(value) {
$scope.leftButtons = value;
if($scope.doesUpdateNavRouter) {
$scope.$emit('navRouter.leftButtonsChanged', $scope.rightButtons);
$scope.$emit('navRouter.leftButtonsChanged', $scope.leftButtons);
}
});

// watch for changes in the right buttons
var rightButtonsGet = $parse($attr.rightButtons);
$scope.$watch(rightButtonsGet, function(value) {
$scope.rightButtons = value;
if($scope.doesUpdateNavRouter) {
$scope.$emit('navRouter.rightButtonsChanged', $scope.rightButtons);
}
});

// watch for changes in the title
Expand Down
10 changes: 9 additions & 1 deletion js/ext/angular/test/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@
$scope.headerTitle = 'A really really really really really long title here';
$scope.leftButtons = [
{
text: 'Hello',
content: 'Hello',
click: function(e) {
console.log('Click button');
}
}
]
$scope.rightButtons = [
{
content: 'Hello',
click: function(e) {
console.log('Click button');
}
Expand Down
2 changes: 1 addition & 1 deletion js/ext/angular/test/navAndTabs.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h3>{{pet.title}}</h3>
</tab>

<!-- Adoption tab -->
<tab title="Adopt" icon="icon ion-heart" ng-controller="AdoptCtrl" right-buttons="buttons">
<tab title="Adopt" icon="icon ion-heart" ng-controller="AdoptCtrl" left-buttons="leftButtons" right-buttons="buttons">
<content has-header="true" has-tabs="true">
<div class="padding">
<h2>Adopt a pet today.</h2>
Expand Down
11 changes: 10 additions & 1 deletion js/ext/angular/test/navRouter.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</pane>

<script id="page1.html" type="text/ng-template">
<nav-page title="'Bears'" hide-back-button="true">
<nav-page title="'Bears'" hide-back-button="true" right-buttons="rightButtons">
<content has-header="true">
<h1>Page 1</h1>
<span>{{num}}</span>
Expand Down Expand Up @@ -76,6 +76,15 @@ <h1>Page 3</h1>

.controller('Page1Ctrl', function($scope) {
$scope.num = Math.floor(Math.random() * 100);

$scope.rightButtons = [
{
text: 'Hello',
click: function(e) {
console.log('Click button');
}
}
]
});


Expand Down

0 comments on commit a83b573

Please sign in to comment.