1

I'm using Angular UI bootstrap's datepicker , and when I change programmatically the date the view doesn't change, when I'm in 30 Novembre and I programmatically change the date to 2 December, the date change but the view still fixed in November, here's how I code the next date button.

$scope.right=function(){
    if($scope.viewmodel.timeResolution=='yearly')
        $scope.dt.setFullYear($scope.dt.getFullYear()+1);
    else if($scope.viewmodel.timeResolution=='monthly')
        $scope.dt.setMonth($scope.dt.getMonth()+1);
    else if($scope.viewmodel.timeResolution=='daily') {
        $scope.dt.setDate($scope.dt.getDate() + 1);
    }
    $scope.changedValue();
};

Html :

 <uib-datepicker ng-model="dt" id="dp" datepicker-mode="mode" init-date="initDate" show-weeks=false max-mode="maxMode"  min-date="minDate" max-date="maxDate" min-mode="minMode" class="well well-sm"  ng-change="changedValue(viewmodel.dt)"></uib-datepicker>

how can I simulate a refresh view everytime I change the date programmatically on the datepicker ?

3
  • can you add the html code for datepicker? Commented Jan 7, 2016 at 12:28
  • @azelix is there business rule to add date? are you try to disable weekend ? Commented Jan 7, 2016 at 12:30
  • @JoaozitoPolo I added it Commented Jan 7, 2016 at 13:02

2 Answers 2

1

you need to convert again to date. The function set... only returns the timestamp:

$scope.right=function(){
    if($scope.viewmodel.timeResolution=='yearly')
        $scope.dt = new Date($scope.dt.setFullYear($scope.dt.getFullYear()+1));
    else if($scope.viewmodel.timeResolution=='monthly')
        $scope.dt = new Date($scope.dt.setMonth($scope.dt.getMonth()+1));
    else if($scope.viewmodel.timeResolution=='daily') {
        $scope.dt = new Date($scope.dt.setDate($scope.dt.getDate() + 1));
    }
    $scope.changedValue();
};
Sign up to request clarification or add additional context in comments.

3 Comments

I don't know about your changedValue() function, but the datepicker doesn't need any other call to work.
You saved me here, your answer is spot on, now it works nicely, and for the changedValue() it does generate Maps and time series i mean by that it dosent have anything to do with the datepicker itself.
You're welcome. I had some problems with timezone too, using that component, but it can vary according to your backend implementation.
0

To make your overall experince with angular dates better, you should look into moment .js

http://momentjs.com/

It allows you to create, format, add and subtract dates easily and with minimal issues. Using the default date.set functions can cause a lot of issues.

I have a set up like this using moments with no issues

1 Comment

It may be an issue i'll look into that later, but that's not the issue i'm having now, the date change as i wanted it there's no problem with the date but the view of my datepicker dosent follow the date when per example the month change from November to December

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.