下面的代码正在做它应该做的事情:
<div class="form-group">
<label for="file_name" class="col-sm-4 control-label">File names:</label>
<select id="file_name" class="col-sm-8" [(ngModel)]="fileName" name="file_name" required>
<option value="run">use the run name</option>
<option value="other">custom- please specify a name below</option>
<option value="input">use the file input name</option>
</select>
</div>
<div class="form-group" *ngIf="fileName === 'other'">
<label for="custom_name" class="col-sm-4 control-label">File name:</label>
<input class="col-sm-8" type="text" id="custom_name" ngModel name="other_custom_name" required>
</div>
<div class="form-group" *ngIf="fileName === 'run'">
<label class="col-sm-4 control-label">Enter file name:</label>
<label class="col-sm-8" id="run_name">{{ this.runName }}</label>
</div>
<div class="form-group" *ngIf="fileName === 'input'">
<label class="col-sm-4 control-label">File name:</label>
<label class="col-sm-8" id="input_name">{{ this.inputDeckName }}</label>
</div>
如果我选择第二个选项,则会显示一个输入:
但是当我启动应用程序时,没有选择任何项目:
将相对选项设置为 selected 不起作用:
<option value="run" selected>use the run name</option>
你能帮我吗?
谢谢你。
在您的控制器中定义属性 fileName 并将其设置为您要选择的选项的值。在这种情况下,您应该执行以下操作:
public fileName: string = 'run';
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句