【发布时间】:2020-01-10 22:44:31
【问题描述】:
如果有来自 API 的任何数据,我需要在视图中显示带有选定值或默认值的下拉列表。我可以使用添加按钮添加新的下拉菜单。但是我必须从下拉列表中选择一次值,所以它不会重复。
我正在使用 ngFor 循环来显示此下拉菜单,并且我正在使用拼接方法从下拉菜单中删除选定的选项。我在这里面临一个问题
示例:如果我从第一个下拉列表 1 和第二个下拉列表中选择汽车 1,我看不到汽车 1,但如果我再次去下拉 1 并将该选项更改为汽车 2,
在下拉 2 中,我看不到 car 1 和 car 2 选项,因为 splice 从该数组中删除了这些选项。
<mat-select required formControlName="productTypeCode"
(selectionChange)="selectType($event.value)">
<mat-option>Select</mat-option>
<mat-option *ngFor="let type of newarrayvalues"
[value]="type.code">
{{type.name}}
</mat-option>
</mat-select>
PriorExperience -> form array for this dropdowns
for (let i = 0; i < this.InvestmentTypes.length; i++) {
for (let j = 0; j < this.PriorExperience.controls.length; j++) {
if (this.InvestmentTypes[i].code == this.financialDetailsForm.value.piExperience[j].productTypeCode) {
// this.removedValues.push(this.newarrayvalues[i])
this.InvestmentTypes.splice(i, 1);
}
}
我只需要删除选定的值,如果我更改了应该只从该数组中删除的任何下拉值
请帮帮我。
【问题讨论】: