Skip to content

Commit

Permalink
fix(sample): use the same variable in the datepicker and from url par…
Browse files Browse the repository at this point in the history
…ams for state `booking.day`

In state `booking`, the model for the datepicker was not associate to the date of state `booking.day`. In case of direct access to this state by URL, the datepicker was not initialized.

Closes #16
  • Loading branch information
ncuillery committed May 30, 2014
1 parent 605f798 commit 646f706
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 3 additions & 0 deletions sample/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ angular.module('ncy-sample', ['ui.router.state', 'ui.bootstrap', 'ncy-angular-br
url: '/:year-:month-:day',
templateUrl: 'views/booking_day.html',
controller: 'BookingDayCtrl',
onExit: function($rootScope) {
$rootScope.reservationDate = undefined;
},
data: {
ncyBreadcrumbLabel: 'Reservations for {{reservationDate | date:\'mediumDate\'}}'
}
Expand Down
4 changes: 2 additions & 2 deletions sample/controllers/booking_day.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
angular.module('ncy-sample')
.controller('BookingDayCtrl', function($scope, $stateParams, rooms) {
$scope.reservationDate = new Date($stateParams.year, $stateParams.month - 1, $stateParams.day);
.controller('BookingDayCtrl', function($scope, $rootScope, $stateParams, rooms) {
$rootScope.reservationDate = new Date($stateParams.year, $stateParams.month - 1, $stateParams.day);

$scope.getRoom = function(id) {
return _.findWhere(rooms, {roomId: parseInt(id)});
Expand Down
2 changes: 1 addition & 1 deletion sample/controllers/booking_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ angular.module('ncy-sample')
// Some hardcoded data ;
$scope.reservations = reservations;

$scope.$watch('reservationFilter', function(newValue) {
$scope.$watch('reservationDate', function(newValue) {
if(newValue) {
$state.go('booking.day', {year: newValue.getFullYear(), month: newValue.getMonth() + 1, day: newValue.getDate()});
}
Expand Down
4 changes: 1 addition & 3 deletions sample/views/booking_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ <h2>Booking</h2>

<div class="row">
<div class="span6">
<div ng-model="reservationFilter">
<datepicker date-disabled="!between(date).length" />
</div>
<datepicker date-disabled="!between(date).length" ng-model="reservationDate" />
</div>
<div class="span6" ui-view>

Expand Down

0 comments on commit 646f706

Please sign in to comment.