Angularjs 控制器在角度指令中未定义
我需要对我的角形文本字段中的日期字段进行自定义验证。我正在使用Angularjs 控制器在角度指令中未定义,angularjs,angularjs-directive,angularjs-forms,Angularjs,Angularjs Directive,Angularjs Forms,我需要对我的角形文本字段中的日期字段进行自定义验证。我正在使用angular uidatepicker元素进行显示。对于验证,我创建了名为validatedate的自定义指令,我想在其中编写自定义逻辑。我面临两个问题: 指令中的ctrl是未定义的 每次输入字段中出现当前未发生的更改时,都应调用该指令。该指令在加载页面时仅调用一次 我在下面添加代码片段以供参考。请告诉我哪里出了问题 <p class="input-group"> <input type="text" clas
angular ui
datepicker元素进行显示。对于验证,我创建了名为validatedate
的自定义指令,我想在其中编写自定义逻辑。我面临两个问题:
ctrl
是未定义的<p class="input-group">
<input type="text" class="form-control" name="enable_dt" uib-datepicker-popup="{{format}}"
ng-model="enable_dt" is-open="datepickers.enable_dt" min-date="minDate" max-date="maxDate"
datepicker-options="dateOptions" validatedate
close-text="Close" ng-requied="maintainanceForm.enable_dt"/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event,'enable_dt')">
<i class="glyphicon glyphicon-calendar"></i></button>
</span>
ctrl是在哪里定义的?你能试试这个吗?要求:“^ngModel”,ctrl在哪里定义?您能试试吗?要求:“^ngModel”,
'use strict';
angular.module('myApp')
.directive('validatedate', function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
console.log(scope.enable_dt);
console.log(ctrl); //ctrl is undefined
}
};
});