如何循环遍历 *ngFor 中的 select 标签并获取 selected 值
how to loop throught select tags inside *ngFor and get the selected value
我在带有 *ngFor 的 table 中有 select 标签,我想循环每个 select 标签并获取 selected 值,然后如果它符合某些条件
我正在使用 angular 7,我试图用元素 ref 获取 select 标签,然后更改它的值,但这改变了所有 select 标签值,我只想更改一个具体 select 标签值
<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>
在 <option>
中使用您的点击方法 (click)="oldSelect = categorymap.category"
,因为 categorymap.category 属于 <select>
中不可用的类别,并且在 <option>
中开始循环使用这个 -
<option *ngFor="let category of categories" (click)="oldSelect = category.name" [value]="category.name" >
{{category.name}}
</option>
我在带有 *ngFor 的 table 中有 select 标签,我想循环每个 select 标签并获取 selected 值,然后如果它符合某些条件 我正在使用 angular 7,我试图用元素 ref 获取 select 标签,然后更改它的值,但这改变了所有 select 标签值,我只想更改一个具体 select 标签值
<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>
在 <option>
中使用您的点击方法 (click)="oldSelect = categorymap.category"
,因为 categorymap.category 属于 <select>
中不可用的类别,并且在 <option>
中开始循环使用这个 -
<option *ngFor="let category of categories" (click)="oldSelect = category.name" [value]="category.name" >
{{category.name}}
</option>