I couldn't figure out what is correct way to make angular 2, BreezeJs and OData to work together
I followed instructions from this npm package: https://www.npmjs.com/package/breeze-bridge-angular2
Also I added link to the OData library.
and my code for initializing OData adapter look like this:
config.initializeAdapterInstance('dataService', 'webApiOData', true);
this._em = new EntityManager('http://localhost:7248/api');
this._em.fetchMetadata((schema) => {
console.log('schema', schema);
var collectionPointType = this._em.metadataStore.getEntityType("ClientBrowse");
(<any>collectionPointType).setProperties({ autoGeneratedKeyType: AutoGeneratedKeyType.Identity });
});
but unfortunally it didn't work.
What I have found is that breezejs is trying to resolve library OData in function __requireLibCore(libName)
, it looks in global.window
but this variable is undefined.
I'm not sure how does global.window initialize, but seems it should be link to global window object. I guess because of some angular 2 isolation it doesn't have direct access to window.
How can I overcome this problem? For sure one of the solution is make monkey patch but I'm doubt it is way to go.
You are missing the datajs dependency. The Breeze OData adapters require datajs.
npm install datajs --save
Then add it to your systemjs.config.js
map: {
...
'datajs': 'npm:datajs'
},
packages: {
...
'datajs': {
main: 'index.js',
defaultExtension: 'js'
}
}
Then import it in your application, so it gets loaded.
import { config } from 'breeze-client';
import 'datajs';