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
especially I need the "range" -from/to . option
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
especially I need the "range" -from/to . option
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>
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>
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.CommentedAug 20, 2017 at 14:32