Reputation: 152
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.
Upvotes: 0
Views: 73
Reputation: 17492
2 things:
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:datepickerLocal
is wrong, should be : datepicker-local
Upvotes: 1