按照这段代码:
<label class="checkbox-label">
<input name="radio1" type="radio"
ng-model="myModel.radio"
required ng-required="true"
value="1">
</label>
<label class="checkbox-label">
<input name="radio1" type="radio"
ng-model="myModel.radio"
required ng-required="true"
value="2">
</label>
<input type="number" name="result" class="form-control input-sm" ng-model="myModel.result"
required ng-required="true" ng-pattern="/^[0-9]+(\.[0-9]{1,2})?$/" step="0.1" min="0" max="100">
我需要根据选择将&ng-pattern
设置step
为接受一位小数 (0.1) 或两位小数 (0.01)radio1
任何人都知道如何解决这个问题?
更新 我已经创建了一个指令来执行此操作,但更改模式后不会触发验证(Angular 1.2)
app.directive('stepChange', function () {
return {
link: function link(scope, element, attr) {
element.bind('change', function () {
var el = angular.element(attr['target']);
el.attr('step', attr['step']);
el.attr('pattern', attr['pattern']);
el.val(attr['val']);
el.trigger();
});
}
}
});