0

I'm new to Angular, I have an object that returns with some data, I want to customize the values of the data, for example the object is as per below

data.json

status: {
    STATUS_ACTIVE
}

I want to convert this to "Active" instead, this object returns with multiple values such as STATUS_ACTIVE, STATUS_SUSPENDED etc...

I would appreciate your assistance in helping me achieve this using the below code, and thanks in advance.

employees.component.ts

exportAsXLSX(): void {
this.PDFvalidation().forEach(element => {
  this.XLSXData.push(
    {
      "Status": element.status
    }
  )
});
this.excelService.exportAsExcelFile(this.XLSXData, 'Employees');
}
2
  • Try "Status": "Active" Commented Feb 4, 2020 at 13:35
  • Assuming XLSXData is a javascript object and you want the additional property at the top level of the resultant json, you should just need to do XLSXData.Status = element.status Commented Feb 4, 2020 at 13:43

1 Answer 1

1

I would recommend using Enums in this situations.

For example:

enum StatusResolver {
   'STATUS_ACTIVE' = 'Active',
   'STATUS_INACTIVE' = 'Inactive'
}

After you've create your ENUM file for example "status.enum.ts" you can reach it by importing it to your working component.

You can use it like this.

function resolveStatus(status: string, response: StatusResolver): void {
// ...
}

Hope it helps!

Sign up to request clarification or add additional context in comments.

1 Comment

That is the kind of answer I was looking for, thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.