In Angular application, I am unable to read from the service I created using [dataSource].
ERROR TypeError: Cannot convert undefined or null to object ERROR TypeError: Cannot read property 'getService' of undefined
component.ts
import { Component, OnInit } from '@angular/core';
import { RailroadAgreementService } from '../../services/railroad-agreement.service';
import { RRA_ID } from '../../models/RRA_ID';
@Component({
selector: 'app-railroad-agreements',
templateUrl: './railroad-agreements.component.html',
styleUrls: ['./railroad-agreements.component.css'],
})
export class RailroadAgreementsComponent implements OnInit {
public data: RRA_ID[];
constructor(private railroadAgreementService: RailroadAgreementService) {}
ngOnInit(): void {
this.railroadAgreementService.getRRAId().subscribe((data) => {
this.data = data;
console.log(this.data);
})
}
}
component.html
<ejs-treegrid [dataSource]="data">
</ejs-treegrid>
dataarray to an empty array to see if that removes the error. Like so:public data: RRA_ID[] = [];