0

I am trying to intialize the date picker to the textbox using angular JS directive.

Here is my angular JS directive

 var testapp = angular.module('testApp',[]);
 testapp.directive('mydatepicker', function () {
   return {
       restrict: 'A',
       require: 'ngModel',
       link: function (scope, element, attrs, ngModelCtrl) {
        $(element).datepicker({
        dateFormat: 'DD, d  MM, yy',
        onSelect: function (date) {
            scope.date = date;
            scope.$apply();
         }
      });
    }
  };
});

HTML code I wrote :

<body ng-app="testApp" ng-controller="myController">
 // some other html code 
 <input type="text" ng-model="date" mydatepicker />
   <br/>
    {{ date }}
//some other html code
</body>

Datepicker is not getting intialized. Here is the JS Fiddle

http://jsfiddle.net/5ua9guee/19/

In the JS Fiddle I am getting two errors :

  1. Uncaught ReferenceError: jQuery is not defined

  2. Uncaught Error: [$injector:modulerr] Failed to instantiate module App due to:

I tried the existing posts but no one worked for me.

Thank You

2 Answers 2

1

Edited your fiddle a bit. It works.

https://jsfiddle.net/dm5pyfbe/

In your code the controller is missing.

testApp.controller('myController', function($scope){});
Sign up to request clarification or add additional context in comments.

Comments

0

It shows you problem:

Uncaught ReferenceError: jQuery is not defined

Then insert your jquery to src;

<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>

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.