这项工作
<input type="text" aaa="{{field.isRequired | requiredx}}" ng-model="field.input.model">
输出
<input type="text" aaa="required" class="form-control ng-pristine ng-valid" ng-model="field.input.model">
但这不起作用
<input type="text" required="{{field.isRequired | requiredx}}" ng-model="field.input.model">
输出
<input type="text" required="{{field.isRequired | requiredx}}" class="form-control ng-pristine ng-valid ng-valid-required" ng-model="field.input.model">
...
编辑,添加过滤器:
angular.module('appFilters', []).filter('requiredx', function() {
return function(input) {
return input ? 'required' : '';
};
}); 任何人都知道如何使它工作?
答案 0 :(得分:1)
使用ng-required,您无法设置HTML5所需的属性。试试这个:
<input type="text" ng-required="(field.isRequired | requiredx)" ng-model="field.input.model">