简体   繁体   English

在一个下拉列表中选择的值不应出现在 Angular 材质的其他两个下拉列表中

[英]Selected value in one dropdown should not appear in other two dropdowns in Angular material

Selected value in one dropdown should not appear in other two dropdowns in Angular material.在一个下拉列表中选择的值不应出现在 Angular 材质的其他两个下拉列表中。 How to remove the selected value in one dropdown from all other dropdowns?如何从所有其他下拉列表中删除一个下拉列表中的选定值? (I have dynamic dropdown which gets added each time a button in clicked) (我有动态下拉菜单,每次点击按钮时都会添加)

I tried using this https://stackblitz.com/edit/angular-dqvvf5?file=src%2Fapp%2Fapp.component.html but the logic is not working for angular material.我尝试使用此https://stackblitz.com/edit/angular-dqvvf5?file=src%2Fapp%2Fapp.component.html但该逻辑不适用于有角度的材料。

I've taken your Stackblitz and managed to get it working using mat-select instead of the standard HTML select .我已经使用了你的 Stackblitz 并设法使用mat-select而不是标准的 HTML select让它工作。 Please see this Stackblitz for a working demo.请参阅此 Stackblitz以获取工作演示。

The main changes were in the HTML...主要的变化是在 HTML...

HTML HTML

<div *ngFor="let field of fieldArray; index as idx" style="margin-bottom: 8px">
  <mat-form-field appearance="fill">
    <mat-label>Select Language</mat-label>
      <mat-select #selectLang (selectionChange)="selected(selectLang.value,i)">
      <ng-container *ngFor="let lang of languageList" >
        <mat-option *ngIf="selectLang.value === lang.name || !isSelected(lang.name)" [value]="lang.name">
          {{lang.name}}
        </mat-option>
      </ng-container>
    </mat-select>
  </mat-form-field>
  <button (click)="deleteFieldValue(idx, selectLang.value)" style="margin-left: 8px">X</button>
</div>

<button (click)="addFieldValue()">Add Select</button>

The Typescript is pretty much the same as in your example, except I've modified the signature of the selected() function to read selected(value: string, idx: number) as you're passing 2 parameters into that from your HTML. Typescript 与您的示例几乎相同,除了我修改了selected()函数的签名以读取selected(value: string, idx: number)当您从 HTML 中传递 2 个参数时。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果一组下拉列表中的任何下拉值更改为等于其他下拉选择的值,则应删除整个其他下拉列表 - If any dropdown value changed from a group of dropdowns which is equal to other dropdown selected value, then entire other dropdown should be removed 一个下拉值的变化会影响其他下拉 - Change in one dropdown value is affecting other dropdowns 如果选择了一个下拉列表,则修改视图,其他下拉列表将被禁用 - Modify view if one dropdown is selected, other dropdowns to be disabled 使用javascript根据其他下拉列表中的选定值启用或禁用下拉列表 - Enable or disable dropdowns based on selected value in other dropdown using javascript 具有相同选项的多个下拉菜单:如何从其他下拉菜单中删除一个下拉列表的当前选定项目? - Multiple dropdowns with same options: how to remove currently selected item of one dropdown from other dropdowns? angular 材料中的预选下拉列表 - pre selected dropdown in angular material 一个从属下拉代码点火器的两个下拉菜单 - two dropdowns on one dependent dropdown codeigniter Bootstrap 5 Dropdowns:在下拉按钮中获取选定的下拉项目值 - Bootstrap 5 Dropdowns: Get selected dropdown item value in the dropdown button AngularJS依赖的下拉列表:在模型中存储一个值,使用其他值作为下一个下拉列表的源 - AngularJS - dependent dropdowns: storing one value in model, using other as source of the next dropdown 如何基于另一个下拉列表中的选定值填充其他下拉列表中的值 - How to populate values in other Dropdowns based on selected values in another Dropdown
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM