-2

I have a JSON Object in my app.component.ts with several values in it with different indices at the end like

 component.JSONObject.Q_HH_44

In a different post( Angular 5 Dynamic variable name ) I read i could change the variable name dynamically in the HTML-Template like such:

{{this['component.JSONObject.Q_HH_' + component.id]}}

However this doesn't seem to work for me and I dont't get why. I think the problem is the this but without the string is written instead of dispayling the variable's value

Here's a Stackblitz with my struggle and all cases I thought could work https://stackblitz.com/edit/angular-ivy-zqlub5?file=src/app/app.component.html

1 Answer 1

0

I played with your stackblitz and got what you want:

<p>
  {{obj.col1['Attribute' + values[1]]}}
  <!-- only String -->
</p>
<p>
  {{obj.col1['Attribute' + values[1]]}}
  <!-- nothing at all -->
</p>

You can't use dots in string to get json objects, js doesn't work this way.

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

Comments

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.