reyesoft / ngx-jsonapi

JSON API client library for Angular 5+ 👌 :: Production Ready 🚀
https://ngx-jsonapi.reyesoft.com/
MIT License
101 stars 52 forks source link

`Autoregister` deprecated but still in readme.md #273

Open DaanVanVugt opened 4 years ago

DaanVanVugt commented 4 years ago

I am trying to install this in a new Angular 9 app, following the instructions in the README, but I see that @Autoregister() has been deprecated.

What is the new way to register Services?

DaanVanVugt commented 4 years ago

Interestingly the changelog and decorators/autoregister.js both state since version 3.0.0, but it's already out of 2.1.15.

I'm getting this kind of error:

The relationship relation_alias? (type event) cant be generated because service for this type has not been injected. 2 ngx-jsonapi.js:886

ERROR TypeError: "resource.toObject is not a function"
    toResourceElements ngx-jsonapi.js:1635
    collectionResourcesToElements ngx-jsonapi.js:1620
    collectionResourcesToElements ngx-jsonapi.js:1617
    saveCollection ngx-jsonapi.js:1579
    getAllFromServer ngx-jsonapi.js:3013
DaanVanVugt commented 4 years ago

Interestingly the changelog and decorators/autoregister.js both state since version 3.0.0, but it's already out of 2.1.15.

I'm getting this kind of error:

The relationship relation_alias? (type event) cant be generated because service for this type has not been injected. 2 ngx-jsonapi.js:886

ERROR TypeError: "resource.toObject is not a function"
    toResourceElements ngx-jsonapi.js:1635
    collectionResourcesToElements ngx-jsonapi.js:1620
    collectionResourcesToElements ngx-jsonapi.js:1617
    saveCollection ngx-jsonapi.js:1579
    getAllFromServer ngx-jsonapi.js:3013

So this error for me was actually caused by the client and server having a different meaning about pluralization of type names. I had the option of changing it server-side to the plural (events) and it works now.

I also added

    constructor() {
      super();
      this.register();
    }

to my EventsService.