I have an input field with an attached Angular UI datepicker, and I have also added two buttons below to change the date "day by day".
Here is the input section on my page:
<p class="input-group">
<span class="input-group-addon hidden-xs">From</span>
<input type="text" class="form-control text-center" datepicker-popup="{{format}}" ng-model="parent.dtFrom" ng-change="refresh(0)" show-button-bar="false" is-open="opened1" max-date="maxDate" datepicker-options="dateOptions" ng-required="true" close-text="Close" readonly />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event, 'opened1')"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
And here are the buttons for changing it:
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 btn-group" role="group" >
<div class="text-center" >
<button type="button" class="btn btn-default btn-outline glyphicon glyphicon-chevron-left text-center previousdate" ng-click="addDayFrom(-1)"></button>
<button type="button" class="btn btn-default btn-outline glyphicon glyphicon-home text-center todaydate" ng-click="DateFromToday()"></button>
<button type="button" class="btn btn-default btn-outline glyphicon glyphicon-chevron-right text-center nextdate" ng-click="addDayFrom(1)" ng-show="parent.dtFrom < todate" ></button>
</div>
</div>
This is how I initialize dtFrom
at the beginning of my controller:
$scope.parent={
dtFrom : new Date(),
dtTo : new Date()
};
And this is the function to change dtFrom
:
$scope.addDayFrom=function(day){
$scope.parent.dtFrom.setDate($scope.parent.dtFrom.getDate() + parseInt(day));
console.log($scope.parent.dtFrom);
};
It changes the value in $scope.parent.dtFrom
but the model isn't updated in the input.
For example, if today's date is 12/05/2015
.
If I click the previous button once, $scope.parent.dtFrom
will be 11/05/2015
.
This reflects correctly everywhere except in the input field.
I believe it may be a scope issue, but I can't pinpoint where it's happening. Do you have any suggestions on how to fix this?
Edit: View image here: