如何知道Angular 6材质MatTable中选定单元格的索引?

时间:2018-09-06 11:06:16

标签: angular-material angular6

我正在使用Angular 6创建有关在线测验的Web应用程序,其中包含一些问题,其选项看起来像一张桌子。我已经使用MatTableSourcedata显示行和列的内容,有些列是一个复选框,需要选中以进行选择。 这是列def代码:

<!-- Checkbox Column --> 
<ng-container matColumnDef="select5">
<th mat-header-cell *matHeaderCellDef> Always </th>
<td mat-cell *matCellDef="let row ;let i = index;">
<div *ngFor="let number of question.options">
<mat-checkbox [(ngModel)]="option.number" (change)="onSelect(question, 
option);">
</mat-checkbox>
</div>
</td>
</ng-container>

这是onSelect方法:

onSelect(question: Question, option: Option) {
if (question.questionTypeId === 3) {
this.config.requiredAll = true;
question.options.forEach((x) => { if (x.id !== option.id) x.selected = 
false; });
this.option.number = this.selection.selected.length;
}
else {
this.config.requiredAll = false;
}
console.log(question.options);
}

如果您需要更多代码或更多说明,请告诉我,我必须知道如何将所选单元格索引分配给选项号。

0 个答案:

没有答案