简体   繁体   中英

javascript - AngularJS - UI Bootstrap Datepicker

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

在此处输入图片说明 How can I fix this? am clueless. Kindly pls help me get through this.

Thanks in advance.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM