[英]Angular [disabled] does nothing
I use angular 6.2.1 我使用角6.2.1
it should disable the submit button but it does nothing ... 它应该禁用提交按钮,但它什么都不做...
this does nothing [disabled]="!heroForm.form.valid" but this [disabled]="heroForm.form.valid" it works but it's not what i want 这什么都不做[disabled] =“!heroForm.form.valid”,但此[disabled] =“ heroForm.form.valid”可行,但这不是我想要的
when inputs are empty it should disable the button but it doesn't 当输入为空时,应禁用该按钮,但不要
it disable the button when [disabled]="heroForm.valid" when the form is valid but it's not what i want. 当表单有效时,当[disabled] =“ heroForm.valid”时,它禁用按钮,但这不是我想要的。 I don't know why it's valid when inputs are empty i use required in every input
我不知道输入为空时为什么有效,我在每个输入中都需要使用
<form #heroForm="ngForm" (ngSubmit)="hola()">
<div class="form-row">
<div class="form-group col-md-6">
<label for="inputEmail4">First Name</label>
<input type="text" class="form-control" placeholder="First name"
required>
</div>
<div class="form-group col-md-6">
<label for="inputEmail4">Last Name</label>
<input type="text" class="form-control" placeholder="Last name"
required>
</div>
</div>
<button type="submit" class="btn btn-outline-primary"
[disabled]="!heroForm.form.valid">Sign in</button>
</form>
Can you try [disabled] = “heroform.invalid”
您可以尝试
[disabled] = “heroform.invalid”
Here is an example https://stackblitz.com/edit/angular-symxeg?file=src%2Fapp%2Fapp.component.html 这是一个示例https://stackblitz.com/edit/angular-symxeg?file=src%2Fapp%2Fapp.component.html
you are missing the ngModel property and the name property on the input fields and thats why ngForm doesn't know what to validate 您在输入字段上缺少ngModel属性和name属性,因此ngForm不知道要验证什么
How about 怎么样
<button type="submit" class="btn btn-outline-primary"
[disabled]="!heroForm.valid">
Sign in
</button>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.