I'm trying to create a base component with some default methods used in list page, so this is my ts file:
export abstract class BaselistComponent<T> implements OnInit {
source: LocalDataSource = new LocalDataSource();
constructor(private service: BasecrudService<T>,
private notification: NotificationService) {
}
ngOnInit(): void {
this.service.findRecords().subscribe((data: T[]) => {
this.source.load(data);
});
}
}
And now i have the Component that use this base:
@Component({
selector: 'ngx-unidade',
templateUrl: './unidade.component.html',
styleUrls: ['./unidade.component.scss'],
})
export class UnidadeComponent extends BaselistComponent<Unidade> {
constructor(service: UnidadeService, notification: NotificationService) {
super(service, notification);
}
}
When i try to execute my APP i got Cannot read property 'findRecords' of undefined i know this error occur because this.service is undefined but i don't know why, i already declared it.
This is my service base:
export abstract class BasecrudService<T> {
constructor(private http: HttpClient, private adapter: Adapter<T>) {
}
abstract getPrefixURL(): string;
findRecords(): Observable<T[]> {
return this.http.get(`${environment.apiUrl}/${this.getPrefixURL()}/pagina/0`).pipe(
map((data: any) => data.registros.map(item => this.adapter.adapt(item))),
);
}
}
And the service Impl:
@Injectable({
providedIn: 'root',
})
export class UnidadeService extends BasecrudService<Unidade> {
constructor(http: HttpClient, adapter: Adapter<Unidade>) {
super(http, adapter);
}
getPrefixURL(): string {
return 'unidades';
}
}
Edit 1
This is my console.log(this), note that my service is undefined
Edit 2 This is my project complete source: https://github.com/rlanhellas/safepark-front
