Issue
Is there a way to simplify this ngClass?
edit? - This one works finevalue ===- This is a child component. Each of the two parent components pass thevalueproperty down as an @Input. Child component 1 has areleasedproperty. Child component 2 does not have thereleasedproperty.- If the
valueisvalue1AND thereleasedproperty istrue, no class is added. However, if thereleasedproperty isfalseadd a class calledclass-3. - If the
valueisvalue2, always addclass-3as there is noreleasedproperty.
The below works, but it feels like it could be streamlined.
<div [ngClass]="[
edit ? 'class-1' : 'class-2',
value === 'value1' && released ? '' : 'class-3',
value === 'value2' ? 'class-3' : ''
]">
Solution
You can optimise a part of it by moving to [class], much shorter and concise:
<div [class.class-3]="(value === 'value1' && !released) || value === 'value2'"
... /the rest of the ngClass for edit
</div>
or keep it all in ngClasse. It can be also shorter:
<div [ngClass]="[
edit ? 'class-1' : 'class-2',
released ? value != 'value1' || value==='value2'? : 'class-3' : ''
]">
Answered By - Vega
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.