I need to be able to pass a dynamic string using the fieldName in order to get an attribute within the item object. In order to make it easy to duplicate the issue I have given a small example. The problem is this syntax works properly with angular 12.2.5 as I checked but did not work with angular 12.0.0 or below. I can simply call a function but I know this is not good for performance. Is there an alternate way to write this syntax for older angular applications?
HTML
<p [style.background]="item?.[fieldName]">
Some Text
</p>
ts
item = { warn: 'yellow', success: 'green', error: 'red' };
fieldName = 'success';
Error looks like this
Parser Error: Unexpected token [, expected identifier or keyword at column 20 in [{background: item?.[fieldName]}]