0

Am new to AngularJS. I want to implement datepicker in my project. Am using angular.min.js version AngularJS v1.5.0-rc.1 ui-bootstrap-tpls-0.12.0.js version 0.12.0. Am getting confused with lot of examples online. How to implement datepicker in angularjs. I used the below code in my application.

app.directive('datepicker', function() {
return {
    restrict: 'A',
    require : 'ngModel',
    link : function (scope, element, attrs, ngModelCtrl) {
        $(function(){
            element.datepicker({
                dateFormat:'dd/mm/yy',
                onSelect:function (date) {
                    scope.$apply(function () {
                        ngModelCtrl.$setViewValue(date);
                    });
                }
            });
        });
    }
}
});

and in my HTML page I used like this.

<input type="text" ng-model="endDate" datepicker>

below is the output am getting

enter image description here How can I fix this? am clueless. Kindly pls help me get through this.

Thanks in advance.

1
  • Is there a reason you are trying to use this directive, instead of just using the datepicker provided by ui-bootstrap? Commented Mar 29, 2016 at 14:25

1 Answer 1

1

Here is the documentation for ui-bootstrap.

Here is their plunkr demonstrating multiple uses of datepicker, including both inline datepicker and the popup version.

HTML for inline datepicker should look something like this

  <div style="display:inline-block; min-height:290px;">
      <uib-datepicker ng-model="dt" class="well well-sm" datepicker-options="inlineOptions"></uib-datepicker>
    </div>

Make sure you are correctly loading/referencing ui-bootstrap and angular in your project.

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

3 Comments

problem is with the ordering of the bootstrap and angular.min.js files. First jQuery, second jQuery-ui and third angular.min.js. By doing this, it started working.
The plnkr link is broken.
If you click the documentation link, then scroll down to the Datepicker section, you can find their plunkr links there as well.

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.