0

I want the option of adding a class to an element. Initially I tried doing class="{{content.options.classes}}". This works if an "options", and a "classes" exist within a "content". However, not every content will have options and classes, which results in an error. So I wanted to create a conditional statement to add the class depending on whether or not it exists/is declared in an external object called "content".

I tried [ngClass]="{'{{content.options.classes}}' : true}", but am getting an interpolation error. What would be a better way to write or go about doing this?

1 Answer 1

1

how about class="{{content?.options?.classes}}"

Sign up to request clarification or add additional context in comments.

1 Comment

I have a component which is doing interpolation of classes like this <i class="ml-3 {{ sizeClass }} spinner-border"></i> I passed the component these classes like this <app-activity-indicator [sizeClass]="'fas spinner-border-sm ml-0 zab aabz'"></app-activity-indicator> But the final result is different then the order I applied the classes <app-activity-indicator [sizeClass]="'fas spinner-border-sm ml-0 zab aabz'"></app-activity-indicator> Difference The classes are put in increasing order and it broke specificity of css I wanted ml-0 to be applied after ml-3 so it can override it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.