有人可以告诉我,为什么选择选项没有正确更新。但无论我更改什么,控制台都会获得正确的值。
具有带有选择选项和保存按钮的表单。每当我改变时,它在我看来显示 [0][0] - [0][0] 。请complete code is here
form name="form" (ngSubmit)="onSubmit()" #f="ngForm" novalidate>
<div class="form-group" contenteditable="false" *ngFor="let val of mockData">
<p>{{val.description}}</p>
<label for="sort" class="col-sm-2 control-label"> select current type </label>
<div class="col-sm-4">
<select [(ngModel)]="saveData.selectedValue1" (change)="currChanged()" name="selectedValue1" >
<option *ngFor='let d of dropDownString' [value]="d.currencyType">
{{d.currencyType}}
</option>
</select>
</div>
<label for="sort" class="col-sm-2 control-label"> select max rate </label>
<div class="col-sm-4">
<select [(ngModel)]="saveData.selectedValue2" (change)="rateChanged()" name="selectedValue2" #selectedValue2 = "ngModel">
<option *ngFor='let c of currencyValue' [value]="c.maxRate">
{{c.maxRate}}
</option>
</select>
</div>
</div>
<button>Save</button>
</form>
请问哪里出了问题,哪些地方需要改变。
注意:我只想单独保存选择的选项值,并且应该描述而不需要对获取响应进行任何更改。目前我正在使用一些硬编码数据。
提前致谢
最佳答案
在 replace
函数中,您需要将占位符替换为 this.saveData.selectedValue1
或 this.saveData.selectedValue2
。 this.saveData
通过 ngModel
绑定(bind)到两个 select
元素的值。
示例:
data.description = data.description.replace(this.prevSelectValue1, this.saveData.selectedValue1);
您还需要相应地更新之前选择的值:
this.prevSelectValue1 = this.saveData.selectedValue1;
Stackblitz here.
关于javascript - Angular 6 - 表单 - 选择选项未正确更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55121393/