2

Hi Friend I want to use jquery ui datepicker plugin in my app I am using http://tamble.github.io/jquery-ui-daterangepicker/ this plugin and want same functionality without any change I have tried something like this code below

(function(){
angular.module('publisher-portal').directive('dateRangePicker', function () {
    return {
         restrict : 'A',
         require: 'ngModel',
         link : function (scope, element, attr, ngModel) {

            element.daterangepicker();
         }
    };
});
})();
<input id="e2" type="text" ng-model="mydate" dateRangePicker/>  

Please suggest me some solution

7

2 Answers 2

3

this is a working snippet (that a close look of how i'm making sure that the jQuery loaded before i call .daterangepiker

more few think you miss on the way

  1. you forgot to put an empty array after you install the module app.module('publisher-portal',[])
  2. you didn't warp the element in $() statement

(function($){
angular.module('publisher-portal',[]).directive('dateRangePicker', function () {
    return {
         restrict : 'A',
         require: 'ngModel',
         link : function (scope, element, attr, ngModel) {

            $(element).daterangepicker();
         }
    };
});
})(jQuery);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.js"></script>
    <script src="https://cdn.jsdelivr.net/momentjs/2.3.1/moment.min.js"></script>
<script src="http://tamble.github.io/jquery-ui-daterangepicker/daterangepicker-master/jquery.comiseo.daterangepicker.js"></script>
    <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/smoothness/jquery-ui.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap/3.1.1/css/bootstrap.min.css">
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/bootstrap/3.1.1/css/bootstrap-theme.min.css">
    <link rel="stylesheet" href="http://tamble.github.io/jquery-ui-daterangepicker/assets/css/styles.css">
    <link rel="stylesheet" href="http://tamble.github.io/jquery-ui-daterangepicker/prettify/prettify.css">
    <link rel="stylesheet" href="http://tamble.github.io/jquery-ui-daterangepicker/daterangepicker-master/jquery.comiseo.daterangepicker.css">
<div ng-app='publisher-portal'>

<input id="e2" type="text" ng-model="mydate" date-range-picker /> 
  </div>

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

2 Comments

Thanks you :) for solution
+1 - The links for the example was helpful to me in answering: stackoverflow.com/questions/54258201/…
1

Check out this pure Angular (no jquery required) date range picker. https://github.com/tawani/taDateRangePicker

enter image description here

Comments

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.