MadPhysicist
MadPhysicist

Reputation: 5831

Generating CSS Class (With Unique Name) Dynamically Using AngularJS

Is it possible to generate a CSS class with a name and then apply it to certain DOM objects using Angular? I am aware of ng-style and other directives. However, it seems that they focus on toggling existing classes or just adding CSS properties to a DOM.

What I am trying to do is pull out some values from database, pass them to a unique CSS class as property values and then apply the class to certain DOM objects.

Any help on this is appreciated.

Upvotes: 0

Views: 181

Answers (1)

Brant
Brant

Reputation: 1788

You can append some value to the end of a string that acts as your class base. On your UI element, do something like

<div class="my-base-class-name-{{myScopeVar}}"></div>

Then you can define all the possible combinations in your stylesheets. Let me know if this answer needs refining based on more input about your problem.

Upvotes: 1

Related Questions