代码之家  ›  专栏  ›  技术社区  ›  sensei

Angular-使用指定的自定义css类和ElementRef获取所有选定的下拉列表值

  •  0
  • sensei  · 技术社区  · 7 年前

    我有两个下拉列表: private elementRef: ElementRef

    <select 
      class="form-control same-group" 
      [(ngModel)]="selected" 
      (ngModelChange)="select($event)" 
      formControlName="age">
      <option 
        *ngFor="let x of collection" 
        [value]="x">
        {{x}}
      </option>
    </select>
    
    <select 
      class="form-control same-group" 
      [(ngModel)]="selected2" 
      (ngModelChange)="select2($event)" 
      formControlName="age2">
      <option 
        *ngFor="let x of collection2" 
        [value]="x">
        {{x}}
      </option>
    </select>
    

    我想选择所有的值到数组中的下拉列表与相同的组类追加如上所示。

    所以,如果在第一个下拉列表中选择的值是“test”,而在第二个下拉列表中选择的值是“test”,我希望有[“test”,“test2”]。

    1 回复  |  直到 7 年前
        1
  •  1
  •   dK-    7 年前

    你可以用 Directive 和查询( ViewChildren )指令。 那么 read

    推荐文章