I'm trying to integrate angular2-odata library. I'm using
@Injectable()
class MyODataConfig extends ODataConfiguration{
baseUrl="http://localhost:54872/odata/";
}
bootstrap(app,[
//some of my other providers etc.
provide(ODataConfiguration, {useClass:MyODataConfig}),
ODataServiceFactory,
]
Problem is that when I try to inject ODataServiceFactory all I get is following error:
EXCEPTION: Error during instantiation of ODataConfiguration! (ClassService -> ODataServiceFactory -> ODataConfiguration). ORIGINAL EXCEPTION: TypeError: Class constructor ODataConfiguration cannot be invoked without 'new'
I googled it and it seems that there is some problem while trying to inject extended class, but I was not able to find solution for this. Any help would be appreciated.
A temporary workaround is to use new on the ODataConfiguration class and then override the baseUrl :
@Component({
templateUrl: './categoryGridOData.component.html',
selector: 'my-category-grid-odata',
providers: [ { provide: ODataConfiguration, useFactory: () => {
let odta = new ODataConfiguration();
odta.baseUrl = 'http://services.odata.org/V4/Northwind/Northwind.svc';
return odta; }
}, ODataServiceFactory ],
styleUrls: [ './carGrid.component.css']
})
export class CategoryGridODataComponent {
For complete code see : https://github.com/StefH/angular2-webpack-starter/blob/_stef_dev/src/app/car/categoryGridOData.component.ts#L18
For some more details see : https://github.com/gallayl/angular2-odata/issues/3
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.