我的表单是作为模板驱动的。
<div class="form-group">
<label for="guitar" class="col-sm-6">Guitar:</label>
<div class="col-sm-6">
<input id="guitar" type="text">
<p *ngIf="template driven template ngIf">Warning!</p>
</div>
</div>
当<input id="guitar">
我输入无效字符时,<input>
将得到样式:
border: 2px solid red
从:
input.form-control.ng-invalid.ng-touched {
border: 2px solid red;
}
并显示<p>Warning!</p>
。
效果很好。
是否可以更改颜色:
<label for="guitar">Guitar:</label>
以红色时,<p>Warning!</p>
会显示和<input>
有一个边界?
您回答了自己的问题:如果出现这种情况,则显示警告消息
*ngIf="template driven template ngIf"
为什么不简单地将此条件应用于您的输入呢?
<input id="guitar" type="text" [class.red]="template driven template ngIf">
.red { color: red; }
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句