1
votes

I want to use this plugin in AngularJS in my export table with filters. is it possible to use it with ng-model and all other uses

the plugin : https://uxsolutions.github.io/bootstrap-datepicker/?markup=input&format=&weekStart=&startDate=&endDate=&startView=0&minViewMode=0&maxViewMode=4&todayBtn=false&clearBtn=false&language=en&orientation=auto&multidate=&multidateSeparator=&keyboardNavigation=on&forceParse=on#sandbox

especially I need the "range" -from/to . option

1
Is is angular or angular js ?Rahul Singh
use ui-bootstrap datepicker, if you are using angularJSgaurav bhavsar
If you want to use bootstrap in combination with angularjs, I advise you to use UI-Bootstrap. These are AngularJS directives for bootstrap. It also has the bootstrap datepicker. angular-ui.github.io/bootstrap/#!#datepickerMitta
UI-bootstarp date picker is not good enough case there is no option to do "range" option like in jqueryfstdv

1 Answers

1
votes

To use uxsolutions bootstrap-datepicker in AngularJS, create a custom directive like this:

app.directive("datepicker", function() {
    return {
      restrict: "A",
      require: "ngModel",
      link: function(scope, elem, attrs, ngModelCtrl) {
          elem.on("changeDate", updateModel);
          elem.datepicker({});

          function updateModel(event) {
              ngModelCtrl.$setViewValue(event.date);
          }
      }
    }
})

Usage:

<div datepicker id="myDatePicker" ng-model="myDate"></div>
<div> {{myDate | date }} </div> 

The DEMO

angular.module("app",[])
.directive("datepicker", function() {
    return {
      restrict: "A",
          require: "ngModel",
          link: function(scope, elem, attrs, ngModelCtrl) {
            elem.on("changeDate", updateModel);
            function updateModel(event) {
              ngModelCtrl.$setViewValue(event.date);
            }
            elem.datepicker({});
          }
    };
})
<script src="//unpkg.com/jquery"></script>
    <script src="//unpkg.com/bootstrap-datepicker"></script>
    <script src="//unpkg.com/angular/angular.js"></script>
    <link href="//unpkg.com/bootstrap-datepicker/dist/css/bootstrap-datepicker.standalone.css" rel="stylesheet">
  <body ng-app="app">
    <div>Selected date: {{myDate | date}}</div>
    <div datepicker ng-model="myDate"></div>
  </body>