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