1

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

georgeawg
  • 48,608
  • 13
  • 72
  • 95
fstdv
  • 53
  • 1
  • 9
  • 1
    Is is angular or angular js ? – Rahul Singh Aug 20 '17 at 07:51
  • use ui-bootstrap datepicker, if you are using angularJS – gaurav bhavsar Aug 20 '17 at 08:05
  • 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. https://angular-ui.github.io/bootstrap/#!#datepicker – Mitta Aug 20 '17 at 09:45
  • Possible duplicate of [Best way to combine AngularJS and Twitter Bootstrap](https://stackoverflow.com/questions/22421707/best-way-to-combine-angularjs-and-twitter-bootstrap). – georgeawg Aug 20 '17 at 11:13
  • UI-bootstarp date picker is not good enough case there is no option to do "range" option like in jquery – fstdv Aug 20 '17 at 14:26

1 Answers1

1

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>
georgeawg
  • 48,608
  • 13
  • 72
  • 95
Ajit Soman
  • 3,926
  • 3
  • 22
  • 41
  • Can I use the ng-model also in the controller ? why do I need ngModel – fstdv Aug 20 '17 at 14:25
  • `ng-model` is used for two way data binding. To get the ng-model value in controller we use `$scope` . For example if you want to get value `myDate` from above example you will use `$scope.myDate` in controller. – Ajit Soman Aug 20 '17 at 14:32