Вот мое решение вашей проблемы. Сначала я добавил компонентный файл ts с фиктивными данными в массиве checkItem типа ClassDescription с интерфейсом ClassDescription. Обратите внимание, что вместо этого я использовал обычный флажок ввода html, я только что проверил на ионной документации, и он будет работать так же, как показано ниже: Ionic Checkbox
<table align="center" >
<tr class="heading" >
<th style="padding: 5px;">Code</th>
<th style="padding: 5px;">Name</th>
<th style="padding: 5px;">Capacity</th>
<th style="padding: 5px;">Remaining</th>
<th style="padding: 5px;">Location</th>
<th style="padding: 5px;">Instructor</th>
<th style="padding: 5px;">Register?</th>
</tr>
<tr *ngFor="let item of classItem">
<td style="border-right-style: dashed;">{{ item.code }}</td>
<td>{{ item.name }}</td>
<td>{{ item.capacity }}</td>
<td>{{ item.remaining }}</td>
<td>{{ item.location }}</td>
<td>{{ item.instructor }}</td>
<td>
<input type="checkbox" [(ngModel)]="item.register" (change)="onChecked(item)"
[disabled]="(item.remaining === 0) && item.register == !true">
<br>
</td>
</tr>
</table>
Мое решение Stackblitz здесь Stackblitz solution
. Далее вы можете добавить свою логику для firebase внутри функции onChecked.
import { Component } from '@angular/core';
interface ClassDescription {
code : string;
name : string ;
capacity: string ;
remaining : number ;
location : string ;
instructor : string;
register: boolean;
}
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
onChecked(item) {
if(item.register)
{
item.remaining = item.remaining - 1 ;
}
else{
item.remaining = item.remaining + 1 ;
}
}
classItem: ClassDescription[]= [
{
'code' : '101',
'name' : 'Micro services',
'capacity': '30',
'remaining' : 5 ,
'location' : 'Engineering dept',
'instructor' : 'Dr. Neha',
'register': false
},
{
'code' : '102',
'name' : 'Computer Science',
'capacity': '30',
'remaining' : 0 ,
'location' : 'Mcarthy hall',
'instructor' : 'Dr. Rob',
'register': false
},
{
'code' : '103',
'name' : 'Programming fundamental',
'capacity': '30',
'remaining' : 5 ,
'location' : 'Harvard hall',
'instructor' : 'Dr. Steven',
'register': false
}
];
}