我有代码:
<input check-value-type-array type-value="node.type_value" type-element="node.type" ng-value="item" class="form-control">
指令:
.directive('checkValueTypeArray', function() {
return {
restrict: 'A',
require: 'ngModel',
scope: {
typeElement: '=',
typeValue: '=',
ngModel: '='
},
link: function(scope, element, attrs, ngModel) {
ngModel.$validators.required = function(v) {}
}
如何获取ng-model inside指令并进行验证:
ngModel.$validators.required = function (v) {
}
答案 0 :(得分:1)
轻微改动,你正在寻找ngModel。$ modelValue:
ngModel.$validators.required = (value) => {
// the value of the model will be ngModel.$modelValue
}