I'm trying to implement an async config loader out of API's metadata and it seems that ODataClient initialization with the metadata is happening too late after the client was injected. Therefore the settings property of the client is undefined and all calls to its methods fails. I wonder how is it supposed to work.
This is a provider:
function provideApiOData(): EnvironmentProviders {
return makeEnvironmentProviders([{
provide: ODataConfigLoader,
useFactory: odataConfigFactory,
deps: [HttpClient],
},
ODataClient,
ODataServiceFactory,
]);
}
function odataConfigFactory(http: HttpClient) {
const url = 'https://services.odata.org/V4/(S(4m0tuxtnhcfctl4gzem3gr10))/TripPinServiceRW/';
const apiConfig: ODataApiConfig = {
name: 'api',
parsers: EDM_PARSERS,
serviceRootUrl: url,
default: true,
options: {
stringAsEnum: true,
stripMetadata: 'minimal',
accept: {
metadata: 'minimal',
},
prefer: {
return: 'representation',
},
},
};
const meta$ = http.get(`${url}$metadata`, {
responseType: 'text'
});
return new ODataMetadataLoader(meta$, apiConfig);;
}
client consumption
@Component({
selector: 'app-metadata',
imports: [AsyncPipe,
JsonPipe
],
templateUrl: './metadata.html',
styleUrl: './metadata.css',
})
export class Metadata<TData> {
private readonly client = inject(ODataClient);
constructor() {
const es = this.client.entitySet<TData>('Photos', `Photos`); // this fails with "can't access property "findApiByName", this.settings is undefined"
}
}
I'm trying to implement an async config loader out of API's metadata and it seems that ODataClient initialization with the metadata is happening too late after the client was injected. Therefore the
settingsproperty of the client is undefined and all calls to its methods fails. I wonder how is it supposed to work.This is a provider:
client consumption