L
L
Ler Den2019-07-01 13:00:10
Angular
Ler Den, 2019-07-01 13:00:10

How to pass parameters to Map in Typescript?

There is a Map of the following form

export const events: Map<EventEnum, EventDo> = new Map([
  [
    EventEnum.SentItem,
    {
      text: '{{ username: link }} gave you {{ itemAmount }}x [{{ itemName }}].',
      category: EventCategoryEnum.Friends,
    },
  ],
  [
    EventEnum.StolenItem,
    {
      text: '{{ username: link }} attacked you and stole your {{ itemName }}.',
      category: EventCategoryEnum.Attacks,
    },
  ],
  [
    EventEnum.ContractDecline,
    {
      text: '{{ username: link }} has declined your contract.  [{{ DETAILS: link }}]',
      category: EventCategoryEnum.Commerce,
    },
  ],
]);

itemAmount, itemName, username - it all comes from the backend.
In the component for each event coming from the backend, I get the corresponding text
this.events.forEach(element => {
      element.text = events.get(element.id).text;
    });

In view I get literally the following:
{{ username: link }} has declined your contract.  [{{ DETAILS: link }}]

Is it possible to somehow pass parameters inside the Map in order to get a readable text at the output?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2019-07-01
@rockon404

The very case when neither Map, nor TypeScript, nor Angular are directly related to the question.
Learn JavaScript. Specifically, work with strings and regular expressions. Just in case, ask one of your senior colleagues, perhaps the project uses a library to work with such patterns.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question