Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 角度6-如何使表单字段仅在用户输入特定值时显示?_Html_Angular_Forms - Fatal编程技术网

Html 角度6-如何使表单字段仅在用户输入特定值时显示?

Html 角度6-如何使表单字段仅在用户输入特定值时显示?,html,angular,forms,Html,Angular,Forms,我有一个带下拉列表的角形表单,列表末尾是选项“Other”。如果用户选择other,我希望出现一个新字段,允许他们输入另一个选项 我尝试过使用ngModel,但了解到不能将其包含在*ngIf语句中,但我认为我的思路可能是正确的 <form class="form-horizontal" role="form" > <tr> <td> <p>Location Type :</

我有一个带下拉列表的角形表单,列表末尾是选项“Other”。如果用户选择other,我希望出现一个新字段,允许他们输入另一个选项

我尝试过使用ngModel,但了解到不能将其包含在*ngIf语句中,但我认为我的思路可能是正确的

<form  class="form-horizontal" role="form" >
       <tr>
           <td>
                <p>Location Type :</p>
           </td>
           <td> <select class="col-md-12 form-control"[(ngModel)]="newmp.locationType" name="locationType">
                   <option value="Outfall">Outfall</option>
                   <option value="Tide Gate">Tide Gate</option>
                   <option value="Upstream">Upstream Pipe</option>
                   <option value="Vault">Vault</option>
                   <option value="Other">Other</option></select>
           </td>
      </tr> 
      <tr *ngIf="locationType == Other">
           <td class="left_td">
                 <p>Other (locationType) :</p>
           </td>
           <td> 
                    <input type="text" name="locationTypeOther"  placeholder="Other (Location Type) "class="col-md-12 form-control" [(ngModel)]="newmp.locationTypeOther" />
           </td>
       </tr> 
</form>
按照我现在的方式,“locationTypeOther”字段将在页面加载时出现,甚至在用户选择选项之前。我可能会错过什么?非常感谢

而不是

<tr *ngIf="locationType == Other">
应该是

<tr *ngIf="newmp.locationType == 'Other'">

对不起,选择“其他”时应该显示哪个字段?你指的是秒内的吗?太好了,谢谢!看来我需要那个模型参考。
<tr *ngIf="newmp.locationType == 'Other'">