[英]Disable md-input-container validation Angular 2
I'm creating a form using Angular 2. When I add the attribute required
to my <input>
I got this: 我正在使用Angular 2创建表单。当我将
required
的属性添加到<input>
我得到了:
What I want is just the second red margin, the one of the input
tag, instead of the first margin that belongs to the md-input-container
. 我想要的只是第二个红色边距,即
input
标签中的一个,而不是属于md-input-container
的第一个边距。
Is there a way to disable one of those margins? 有办法禁用其中一个边距吗?
html code: html代码:
<h2 class="mmm">Create building</h2>
<form #buildingForm="ngForm" (ngSubmit)="onSubmit(buildingForm.value)">
<div class="form-group">
<md-input-container>
<input type="text" #nameRef mdInput required placeholder="Building name" name="name" ngModel>
</md-input-container>
</div>
<button type="submit" md-raised-button color="accent" class="pull-right">{{title}}</button>
</form>
css: CSS:
md-input-container input {
width: 400px;
font-size: 1.5em;
}
As you can see, my css only adapts the container size. 如您所见,我的CSS仅适应容器的大小。
Thanks to @Nehal for the hint. 感谢@Nehal的提示。
I think I just found a solution. 我想我刚刚找到了解决方案。 Not a fancy one though.
虽然不是一个幻想。
When using md-input-container
with an <input mdInput required>
there are two classes that draw the invalid indicator. 当将
md-input-container
与<input mdInput required>
,有两个类可绘制无效指示符。 Those are .mat-input-container
and .mat-input-element
. 这些是
.mat-input-container
和.mat-input-element
。 As you can guess, removing the invalid indicator of one of them is simply as adding 如您所料,删除其中之一的无效指示符就像添加
.(mat-input-container or mat-input-element) {
border-left: none;
}
This allow us to even change the color of these validations. 这使我们甚至可以更改这些验证的颜色。 I hope this will be useful for someone that have the same problem.
我希望这对有相同问题的人有用。
If anyone have a different solution it will be awesome, personally, I don't like CSS tricks. 如果有人有不同的解决方案,那么就个人而言,这将是很棒的,我不喜欢CSS技巧。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.