Angular2 using the Elvis operator on a slash object key

I had parsing problems that are solved using the Elvis operator, but if I have a key that contains a slash, I cannot use the Elvis operator because I need to insert this key in square brackets.

It works if the key is as simple ("firstname")

{{ data?.record?.firstname }} 

Does not work if the key has forward brackets like this ("name / first")

 {{ data?.record?['name/first']}} 

Elvis seems to be unavailable if I use square brackets.

Any workaround? Maybe a way to run forward. designation:

 {{ data?.record?.name\\/first }} 
+6
source share
1 answer

The Elvis operator is available only to . not for other dereference operators, such as [] .

As a workaround, use

 {{ data?.record ? data.record['name/first'] : null}} 
+12
source

All Articles