Search code examples
angulartypescriptngrxngrx-entity

Ignoring unnecessary object properties brought along with a Back-End object


Have a question on ignoring unnecessary object properties brought along with a Back-End model.

Can you plz provide your inputs ?

Let us say that an API is returning below object

export class TodoObject{

public name: string;

public id: number,

public assignedTo:string,

public completed: boolean,

public dueDate:Date

}

In Angular UI I do not require the below two fields

public assignedTo:string,

public dueDate:Date

so can i have an object in Angular UI as below ?

export class TodoObject{

public name: string;

public id: number

public completed: boolean

}

Is it possible to do this in Angular. I know GraphQL has capability for this. Wanted to know if its is possible to achieve this.

Is this possible using Ngrx or other alternative?


Solution

  • You have to manually map the properties.

    const frontEndModel = {
      name: backendModel.name,
      id: backendModel.id,
      completed: backendModel.completed
    }