Is it possible to call a function on an item element inside an ngFor
loop in order to set some properties? Otherwise, I find myself having to loop twice - once in the script and then again in the template - setting temporary properties to a model that should only have specific ones. This results in ugly and redundant code, so I want to outsource the property-setting into a function.
Here's an example:
<StackLayout *ngFor="let item of items">
<Label setProperties(el,item)></Label>
</StackLayout>
and
function setProperties(el,item) {
el.text = item.fullname;
let color = '';
switch(item.state) {
case 'success':
let color = 'green';
break;
case 'fail':
let color = 'red';
break;
}
el.style.color = color;
}
Something along those lines, but more complex in reality ;-)
Thank you in advance!