1 year ago

#190626

test-img

Sfisioza

Managing model types in Angular (CRUD architecture and API typing, base components and services)

Where do I find any complete examples of data management in Angular?

My REST API has about 200 API endpoints and returns some data in this format:

/user/123

{
    id: 123
    lastUpated: '21-12-2021',
    name: 'john'
    surname: 'doe'
    email: 'jd@example.com`
    avatar: 'http://image.jpg'
}

or

/item/123

{
    id: 123,
    number: 'abcdef-asd`,
    name: 'product 1',
    lastUpated: '21-12-2021',
    photos: {
       {
          alt: 'sdfdsf',
          src: 'http:///'
       }
       ....
    }
}

Basically each of these models has a separate Angular module and it's own REST CRUD based on some base classes common for all the services (separate controllers for C R U D operations).

I have a base Angular service (BaseRestApiService) handling all the REST operations for all the API endpoints.

I want to display the data coming from the API using always the same visual appearance. (eg. the user model should be displayed as a clickable name with avatar image), no matter were in the application they are displayed.

How do I:

  • define the models in Angular
  • convert the JSON models coming from the API to the correct Angular model instance (using the base service)
  • define the formatters for the columns (eg. format all the Date data type the same way)
  • display the User always the same way
  • prevent code duplication
  • prevent defining all the models at the application start (lazy loading of the modules)

I'm assuming that the base C R U D controllers are the same for all the API services, so I can't just harcdode the model types in the base service and in the HTML, like:

<app-user-model></app-user-model>
<app-item-model></app-item-model>

How do I do it the Angular way?
Is there any open source app to be used as a reference?

If this matters, I'm using Angular Material too.

angular

service

model

architecture

reusability

0 Answers

Your Answer

Accepted video resources