I am working on the task to fetch data using REST API in angular 8.0.0, while doing so i am getting errors as below:
My task was to display data into the Mat Table on page.
item.ts
import { Execution } from './execution';
export class Items {
items: Exec[];
}
execution.ts
export class Exec {
test: number;
test1: string;
}
execution.component.ts
export class ExecutionComponent implements OnInit {
runData: Items;
constructor(private executionService: ExecutionService) { }
displayedColumns: string[] = ['test', 'test1'];
//@ViewChild(MatSort, { static: true }) sort: MatSort;
dataSource = new MatTableDataSource<Execution>(this.runData.items); //error showing at this point
ngOnInit() {
this.executionService.getArtifactDetails().subscribe(
(response:Items) => {
this.runData = response;
console.log(this.runData);
}
);
}
}
Sample JSON
{
"items": [
{
"test": 1,
"test1": "ABC"
},
{
"test": 2,
"test1": "EFG",
]
}