如果用户未填充输入字段,我希望禁用该按钮.我添加了一个条件"(name.value.length === 0 || email.value.length === 0)"它会在加载时禁用该按钮,但是当在文本字段中输入值时,不会删除禁用的
<section class="container col-md-12 col-md-offset-3">
<h1>Add Users</h1>
<form class="form-inline">
<div class="form-group">
<label for="exampleInputName2">Name</label>
<input type="text" class="form-control" id="exampleInputName2" placeholder="Jane Doe" #name>
</div>
<div class="form-group">
<label for="exampleInputEmail2">Email</label>
<input type="email" class="form-control" id="exampleInputEmail2" placeholder="jane.doe@example.com" #email>
</div>
<button type="submit" [disabled]="(name.value.length === 0 || email.value.length === 0)" class="btn btn-default" (click)="getValues($event, name, email)">Add Data</button>
</form>
</section>
<section class="container">
<h3>Users Details</h3>
<table class="table">
<thead>
<tr>
<th class="col-md-6">Name</th>
<th class="col-md-6">Email</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let data of dataArr">
<td>{{data.name}}</td>
<td>{{data.email}}</td>
</tr>
</tbody>
</table> …Run Code Online (Sandbox Code Playgroud) angular ×1