试图在选定下拉更改值之后获取表的第一列td值,但不起作用。 我想在角度6中选择下拉菜单后获得第一列td值。 我在下面给出了我的代码。任何人都有想法吗?请帮助找到解决方案。
<table class="table table-striped table-hover" id="wrapperTbl">
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Job</th>
<th>YearJoined</th>
<th>Missions</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let astronaut of astronautsToBeSelected" class="clickable">
<td (click)="selectAstronaut(astronaut)">{{astronaut.id}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.name}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.job}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.year_joined}}</td>
<select (change)="selected()">
<option *ngFor="let mission of astronaut.missions" [selected]="mission.name == 'back'">{{mission}} </option>
</select>
</tr>
</tbody>
答案 0 :(得分:1)
您可以执行以下操作-
<tbody>
<tr *ngFor="let astronaut of astronautsToBeSelected" class="clickable">
<td (click)="selectAstronaut(astronaut)">{{astronaut.id}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.name}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.job}}</td>
<td (click)="selectAstronaut(astronaut)">{{astronaut.year_joined}}</td>
<td><select (change)="selected($event, astronaut.id)">
<option *ngFor="let mission of astronaut.missions" [selected]="mission.name == 'back'">{{mission}} </option>
</select>
</td>
</tr>
</tbody>
当您要访问任何事件时,将需要html中的$ event。您还可以传递所需的其他参数。
selected(event, id){
//tbal id is wrapperTbl
alert(event.target.value + '|' + id )
}
希望这会有所帮助。