Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Angular display conditional text in html including conditional data

I know in Angular2+ we can create condition in html like this:

  <p>{{ dynamicData.value? dynamicData.value : dynamicData.default}}</p>

Also we can do something like this:

  <p>{{ dynamicData.value? 'text 1' : 'text 2'}}</p>

But I would like to combine this two solutions and I have no idea how to do this. In general I would like to do something like this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

  <p>{{ dynamicData.value? 'Dynamic data value is equal: {{dynamicData.value}}' : 'no dynamic data'</p>

Have you any idea how to handle this text interpolation?

>Solution :

You do not need to use interpolation within interpolation, you already have access to variables and can try something as below:

<p>{{ dynamicData?.value ? ('Dynamic data value is equal: ' + dynamicData?.value) : 'no dynamic data'}}</p>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading