我编写了自定义指令,用于检查输入字段中的输入文本。并突出显示有错误的输入。
.directive('checkValueType', function () {
return {
restrict: 'E',
require: 'ngModel',
scope: {
ngModel: '='
},
link: function (scope, element, attrs, ngModel) {
var status = false;
var type_value = attrs.typeValue;
ngModel.$validators.required = function(v) {
switch (type_value){
case "integer":
status = isInt(v);
break;
}
return status;
};
}
};
})
我称之为:
<input check-value-type type-value="{{node.type_value}}" ng-model="node.value">