0

I'm trying to understand how Typescript and HTML are passing data.

(Typescript)

  public getContactByTradingPartnerId(tradingPartnerId: number):string {
    const map = {
        1001 : "[email protected]",
        2 : "[email protected]",
        11 : "[email protected]"
    }
    return map[tradingPartnerId] ?? "A contact has not been found for this trading partner."

(HTML)

<div class="example-element-description">
    {{element.tradingPartnerId}}
</div>

How can I pass the element.tradingpartnerid to the typescript function getContactByTradingPartnerId so that it renders the contact? (Example. the element.tradingPartnerId is 1001 so it renders [email protected] on the UI).

1
  • from where is your element comes? Commented Jun 15, 2021 at 14:33

2 Answers 2

3

You can set inner HTML values of element in angular like: [innerHtml]="value"

So you can try:

<div class="example-element-description" 
    [innerHtml]="getContactByTradingPartnerId(element.tradingPartnerId)">
</div>
Sign up to request clarification or add additional context in comments.

1 Comment

This is the right answer.
0

You can just call the typescript method within the {{}} (assuming the html view is linked to an angular component containing your function).

<div class="example-element-description">
    {{getContactByTradingPartnerId(element.tradingPartnerId)}}
</div>

Usually you'll want to avoid calling functions in the templating accolades.

1 Comment

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.