breeze-client icon indicating copy to clipboard operation
breeze-client copied to clipboard

Example of DataServiceODataAdapter

Open Tiberriver256 opened this issue 6 years ago • 6 comments

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();
}

Tiberriver256 avatar Jul 12 '19 02:07 Tiberriver256

Specifically I'm trying to get a sample working with the OData v4 TripPin sample service: https://services.odata.org/TripPinRESTierService

Tiberriver256 avatar Jul 12 '19 02:07 Tiberriver256

What were the errors?

steveschmitt avatar Jul 12 '19 04:07 steveschmitt

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)

Tiberriver256 avatar Jul 12 '19 12:07 Tiberriver256

In addition to breeze, you will need the datajs library. It's not an npm package, and will need to be loaded by a

steveschmitt avatar Oct 16 '19 06:10 steveschmitt

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

Rodbourn avatar Dec 04 '19 21:12 Rodbourn

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

haoguanjun avatar Jun 21 '20 04:06 haoguanjun