0
我想在我的应用程序中实现一个指令。这是下面的代码。Angular JS Custom Directive not working
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);
});
});
}
};
}
);
这里是HTML文本字段。
<input id="datepicker" type="text" data-ng-datepicker data-ng-options="datepickerOptions" ng-model="user.User.DateOfBirth" datepickerLocal>
我能看到的第一个控制台消息,但howeven指令内的控制台消息没有出现。
反馈将不胜感激。
谢谢.. datepicker-local是我应该认识但忽视的东西。 – LS2 2014-10-10 07:12:04