Example of DataServiceODataAdapter
Hi,
Is there a good example somewhere of using breeze-client@latest with the DataServiceODataAdapter?
Below is what I tried but got a lot of errors with:
constructor(http: HttpClient) {
// the order is important
ModelLibraryBackingStoreAdapter.register();
UriBuilderODataAdapter.register();
config.registerAdapter('ajax', <any>function() { return new AjaxHttpClientAdapter(http); });
config.initializeAdapterInstance('ajax', AjaxHttpClientAdapter.adapterName, true);
DataServiceODataAdapter.register();
}
Specifically I'm trying to get a sample working with the OData v4 TripPin sample service: https://services.odata.org/TripPinRESTierService
What were the errors?
Error: Unable to initialize OData. Needed to support remote OData services
at Object.requireLib (breeze-client.js:545)
at DataServiceODataAdapter.initialize (breeze-client-adapter-data-service-odata.js:62)
at BreezeConfig._initializeAdapterInstanceCore (breeze-client.js:1582)
at BreezeConfig.initializeAdapterInstance (breeze-client.js:1482)
at Function.register (breeze-client-adapter-data-service-odata.js:59)
at new AppComponent (app.component.ts:40)
at createClass (core.js:27865)
at createDirectiveInstance (core.js:27685)
at createViewNodes (core.js:38315)
at createRootView (core.js:38187)
In addition to breeze, you will need the datajs library. It's not an npm package, and will need to be loaded by a
I added it in app.module.ts below the other breeze imports
import { HttpClient } from '@angular/common/http';
import { NamingConvention } from 'breeze-client';
import { DataServiceODataAdapter } from "breeze-client/adapter-data-service-odata";
import { ModelLibraryBackingStoreAdapter } from 'breeze-client/adapter-model-library-backing-store';
import { UriBuilderODataAdapter } from "breeze-client/adapter-uri-builder-odata";
import { AjaxHttpClientAdapter } from 'breeze-client/adapter-ajax-httpclient';
import 'datajs';
and in the constructor for the AppModule
export class AppModule {
constructor(http: HttpClient) {
// Configure Breeze adapters
ModelLibraryBackingStoreAdapter.register();
UriBuilderODataAdapter.register();
AjaxHttpClientAdapter.register(http);
DataServiceODataAdapter.register();
NamingConvention.camelCase.setAsDefault();
}
}
That did the trick for OData.
Also, this was incredibly useful for going from angularjs to angular 8 with odata
https://github.com/Breeze/northwind-core-ng-demo/blob/master/STEPS.md
UriBuilderODataAdapter use OData that com from datajs, but datajs is to support OData v1-v3, not for OData v4, The TripPin service is OData v4