[英]Validate dynamically generated inputs inside a div
I'm trying to validate dynamically generated inputs, but I do not know how to do this. 我正在尝试验证动态生成的输入,但是我不知道该怎么做。
When I add the div that triggers the directive and inserts the inputs dynamically the div adds the 'has-error' class but does not apply the input style , anyone knows the best way to do this that I'm trying to do? 当我添加触发指令并动态插入输入的div时,div添加了“ has-error”类,但不应用输入样式 , 有人知道我尝试执行此操作的最佳方法吗?
Here is the markup: 这是标记:
<div ng-if="conditionItem.field.id"
ng-class="{true: 'has-error'}[conditionItem.field.hasError]"
dynamic
input-router
source="conditionItem.field"
ng-click="FieldConditionsCtrl.valueTest(conditionItem.field.hasError)"
ng-required="true"
ng-model="conditionItem.situation[$index]">
</div>
Here is the directive how generate the inputs: 这是伪指令如何生成输入:
(function() {
'use strict';
angular
.module('applicationInputs', ['rzModule', 'focus-if', 'ui.utils.masks'])
.directive('inputRouter', inputRouter);
/** @ngInject */
function inputRouter($compile){
return {
restrict: 'EA',
scope: {
ngModel: '=',
source: '=',
placeholder: '@',
tabIndex: '='
},
link: function(scope, element, attrs) {
var canvas = angular.element(element[0]);
scope.source.editable = angular.isUndefined(scope.source.editable) ? true : scope.source.editable === true;
//used by setting to override selected field
if (angular.isDefined(attrs.dynamic)) {
scope.$watch('source', function () {
var html = '<' + scope.source.type + 'input></' + scope.source.type + 'input>';
canvas.children().detach();
canvas.append($compile(html)(scope));
});
} else {
var html = '<' + scope.source.type + 'input></' + scope.source.type + 'input>';
canvas.append($compile(html)(scope));
}
}
}
}
})();
Here is my style: 这是我的风格:
.has-error {
border-color: red
}
Try border: 1px solid red; 尝试边框:1px纯红色; instead of just setting border-color. 而不是仅设置边框颜色。 Border width is 0 by default, so just setting a color isn't enough 边框宽度默认为0,因此仅设置颜色是不够的
Just a couple nitpicky-subjective style comments also: 只是一些挑剔的主观风格的评论也:
I'm a big fan of these style guides for AngularJS: 我非常喜欢AngularJS的这些样式指南:
There's overlap, but take what you like from each. 有重叠,但是从每个中取您想要的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.