我有一个可以获取表达式的自定义验证属性指令,例如:
<input type="text" uiSelectRequired="isParam == true"/>
假设我不能使用隔离范围,我如何在我的指令中评估这个表达式?
谢谢。
angular.module("app").directive('uiSelectRequired', function () {
return {
require: 'ngModel',
link: function (scope, element, attr, ctrl) {
ctrl.$validators.uiSelectRequired = function (modelValue, viewValue) {
var attrbs = attr;
var determineVal;
if (angular.isArray(modelValue)) {
determineVal = modelValue;
} else if (angular.isArray(viewValue)) {
determineVal = viewValue;
} else {
return false;
}
return determineVal.length > 0;
};
}
};
});