0

I am trying to implement a directive in my app. Here is the following code.

    console.log("Directive loaded");
    angular.module("MyApp")
       .directive("datepickerLocal", function($rootScope) {
       console.log("datepickerLocal");
       return {
          restrict: 'E',
          require: 'ngModel',
          link: function(scope, elem, attr, ctrl) {
          ctrl.$parsers.unshift(function(viewValue) {
            var ngModelController = ctrls[0];
            ngModelController.$parsers.push(function (viewValue) {
               viewValue.setMinutes(viewValue.getMinutes() - viewValue.getTimezoneOffset());
               return viewValue.toISOString().substring(0, 10);
            });
         });
       }
    };
  }
 );

And here is the HTML text field.

    <input id="datepicker" type="text" data-ng-datepicker data-ng-options="datepickerOptions" ng-model="user.User.DateOfBirth" datepickerLocal>

I am able to see the first console message, but howeven the console message inside the directive is not appearing.

Feedback will be much appreciated.

0

1 Answer 1

1

2 things:

  1. Your'e restricting the directive to E, saying it should be defined as an element, but you're using it an an attribute. Either change restrict: "E" to A or EA, or use it like:

  1. Directives need to be camel cased when used in html, that is:

datepickerLocal is wrong, should be : datepicker-local

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

1 Comment

Thanks.. datepicker-local was something i should have recognised but overlooked.

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.