After making a get call to my API and receiving a list of objects, I save that data to a property in my DataService for use across components.
Here is the code snippet from my component that calls the service:
getAvailableParameters() {
this.verificationService.getAvailableParameters(this.itemNumbers).subscribe((res => {
this.dataService.availableParameters = res;
}))}
This is the API call:
getAvailableParameters(itemNumbers: string[]){
return this.http.get<BaseResponse<IavailableParameters[]>>(`${this.baseUrl}api/verification/${itemNumbers}`)
}
Below is the property in the DataService where the object should be stored after calling getAvailableParameters:
export class DataService {
public orderInfo: Iorder;
public availableParameters: IavailableParameters[];
}
The response from the API is wrapped in a BaseResponse object, which might be causing issues, defined here:
import { Error } from './Error'
export interface BaseResponse<T> {
isSuccessful: boolean,
error: Error;
results: T;
}
Currently, I am encountering this specific error:
ERROR in src/app/Components/verification-reply/verification-reply.component.ts(28,7): error TS2740: Type 'BaseResponse<IavailableParameters[]>' is missing the following properties from type 'IavailableParameters[]': length, pop, push, concat, and 26 more.
If I remove the base response type, everything works fine, indicating that it may not recognize it as an array. This method of binding to the data service object worked well when the returned object was not an array.
As someone new to this topic, I would appreciate some guidance on resolving this error.