I am brand new to Angular and I'm currently attempting to display all the data and update the value of a checkbox when it is checked or unchecked. Here's my code:
DatasetComponent.ts:
export class DatasetComponent implements OnInit {
displayedColumns: string[] = ['id', 'sentenceWords','isHateSpeech', 'isIronic'];
form: FormGroup;
pageSizeOptions: number[] = [10, 25, 100, 500, 1000];
sentences: MatTableDataSource<any> = new MatTableDataSource();
@ViewChild(MatPaginator) paginator!: MatPaginator;
@ViewChild(MatSort) sort!: MatSort;
(... rest of the TypeScript code ...)
(... continuation of the TypeScript code ...)
and the HTML template:
<form [formGroup]="form">
<div class="m-3">
<table mat-table [dataSource]="sentences" matSort class="mat-elevation-z8">
(... table columns definition ...)
</table>
<mat-paginator
[pageSizeOptions]="pageSizeOptions"
(page)="onPageChange($event)"
showFirstLastButtons
></mat-paginator>
</div>
</form>
(... rest of the HTML code ...)
Below is an error message that I usually encounter. Additionally, the checked values are not being displayed.
ERROR TypeError: Cannot read properties of undefined (reading 'get')
at FacebookDatasetComponent_td_11_Template (facebook-dataset.component.html:20:27)
at ReactiveLViewConsumer.runInContext (core.mjs:10407:13)
at executeTemplate (core.mjs:10947:22)
at refreshView (core.mjs:12468:13)
at detectChangesInView (core.mjs:12632:9)
at detectChangesInEmbeddedViews (core.mjs:12576:13)
at refreshView (core.mjs:12492:9)
at detectChangesInView (core.mjs:12632:9)
at detectChangesInComponent (core.mjs:12608:5)
at detectChangesInChildComponents (core.mjs:12646:9)
Here is a preview of the UI where the API returns JSON responses but the rows are not rendered correctly:
Despite using Reactive Forms, the rows are not rendering properly and the values are not shown as checked in the IsHateSpeech and IsIronic columns.