0

I have a directive for jquery date pickter. It works on Attribute method. But when i change to element it doesn't working. Here are my angular directive code

app.directive('jqdatepicker', function () {
    return {
        restrict: 'E',
        //require: 'ngModel',
        template:'<input type="text" class="cal_datefield">',
         link: function (scope, element, attrs, ngModelCtrl) {
            element.datepicker({
                dateFormat: 'dd/mm/yy',
                onSelect: function (date) {
                    scope.date = date;
                    scope.$apply();
                }
            });
        }
    };
});

My Markup has

<jqdatepicker></jqdatepicker>

Can you help me

Thanks in advance

1 Answer 1

2

It looks something like:

app.directive('jqdatepicker', function () {
      return {
          restrict: 'E',
          //require: 'ngModel',
          replace: true,
          template:'<input type="text" class="cal_datefield">',
           link: function (scope, element, attrs, ngModelCtrl) {
              element.datepicker({
                  dateFormat: 'dd/mm/yy',
                  onSelect: function (date) {
                      scope.date = date;
                      scope.$apply();
                  }
              });
          }
      };
  });

You need to add one another option replace.

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

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.