有人可以告诉我,为什么选择选项无法正确更新。但是无论我进行了什么更改,控制台都能获得适当的价值。

有选择选项和保存按钮的表格。每当我更改时,它在我的视图中显示为[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.selectedValue1this.saveData.selectedValue2this.saveData通过select绑定到两个ngModel元素的值。

例:

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/

10-10 09:06
查看更多