1

I'm using datepicker from here: http://indrimuska.github.io/angular-moment-picker/

How can I set this default value?

<input class="form-control"
       placeholder="Select date: To"
       ng-model="ctrl.datepicker">

What should I write in controller to get default date - today?

$scope.ctrl.datepicker=?;

1 Answer 1

1

You can set today as default date using by passing moment(); only.

So in your case you have to do $scope.ctrl.datepicker = moment();

Below is working example:

HTML:

  <div class="form-control"
       moment-picker="ctrl.div.stringDate"
       format="YYYY-MM-DD"
       locale="en"
       ng-model="ctrl.div.momentDate">
    <a class="pull-right"
       ng-if="ctrl.div.stringDate"
       ng-click="ctrl.div.momentDate = undefined">
      &times;
    </a>
    <span ng-class="{'text-muted': !ctrl.div.stringDate}">
      {{ ctrl.div.stringDate || 'Select a date...' }}
    </span>
  </div>

JavaScript controller:

ctrl.setToday = function (which) {
  ctrl[which].momentDate = moment();
};

Here is complete code: https://plnkr.co/edit/3tf1IeOoZimt9V6HQnSp?p=preview

Sign up to request clarification or add additional context in comments.

Comments

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.