Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ORIGINAL EXCEPTION: TypeError: class constructors must be invoked with |new| #3

Closed
StefH opened this issue Aug 23, 2016 · 1 comment

Comments

@StefH
Copy link
Contributor

StefH commented Aug 23, 2016

Hi

I'm trying to combine several example projects:

My example project can be found at:
https://github.com/StefH/angular2-webpack-starter

However when enabling the my-category-grid-odata component in the "car.component.html" file, I get error like:

ORIGINAL EXCEPTION: TypeError: class constructors must be invoked with |new|
ORIGINAL STACKTRACE:
MyODataConfig@http://localhost:3000/main.bundle.js:1030:10
anonymous/_View_CarComponent0.prototype.createInternal@CarComponent.ngfactory.js:42:34

The providers are loaded as:

@Component({
    templateUrl: './categoryGridOData.component.html',
    selector: 'my-category-grid-odata',
    providers: [ { provide: ODataConfiguration, useClass: MyODataConfig }, ODataServiceFactory ],
    styleUrls: [ './carGrid.component.css']
})
export class CategoryGridODataComponent {

Do you have a clue ?

@gallayl
Copy link
Owner

gallayl commented Aug 24, 2016

Hi,
I think this is related to the build target, which is "es5" in your project. Try out specifying "es2015" if you don't need legacy browser support.
The provide function call syntax is also a bit different, here's the correct one:
providers: [ODataServiceFactory, provide(ODataConfiguration, {useClass: MyODataConfig})],
If you want to keep "es5" as your build target, you can use this dirty workaround:

    providers: [ ODataServiceFactory, provide(ODataConfiguration, {useFactory: () => {
        let odta = new ODataConfiguration();
        odta.baseUrl = 'http://services.odata.org/V4/Northwind/Northwind.svc';
        return odta;
    }}) ],

One thing I've modified, for creating the services please replace "category" with "Categories" cause this will be the OData collection name.

@gallayl gallayl closed this as completed Aug 26, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants