如何循环遍历* ngFor中的选择标签并获取所选值

时间:2019-08-27 08:49:19

标签: angular7

我在带有* ngFor的表中有选择标签,并且我想为每个选择标签循环并获取选择的值,然后如果它符合某些条件则进行更改 我正在使用angular 7,并且尝试使用元素ref获取选择标签,然后更改其值,但是这更改了所有选择标签的值,我只想更改特定的选择标签值

<tr *ngFor="let categorymap of categoriesMap | orderBy:   order:reverse:'case-insensitive'">
            <td scope="row " class="goSubcategory point imageHeader rep-table">
              {{categorymap.saltEdgeCategory}}
            </td>
            <td scope="row" class="point rep-table"  >
              <div class=" m-auto mt-4">
                <select id="e" #e="ngModel" class="browser-default custom-select"   [(ngModel)]="categorymap.category" (click)="oldSelect = categorymap.category"  (change)="mapCategory($event,categorymap.id,categorymap.saltEdgeCategory,categorymap.category)" >
                    <option disabled hidden [value]="null">{{"pages.notMappedYet" | translate}}</option>
                    <option *ngFor="let category of categories"  [value]="category.name" >
                      {{category.name}}
                    </option>
                  </select>
            </div>
            </td>
             </tr>

1 个答案:

答案 0 :(得分:0)

(click)="oldSelect = categorymap.category"中使用您的点击方法<option>,因为categorymap.category属于<select>中不可用的类别,并且<option>中的循环开始使用此方法-< / p>

<option *ngFor="let category of categories" (click)="oldSelect = category.name" [value]="category.name" >
                  {{category.name}}
                </option>