0

I'm trying to add a dynamic class in Angular template and set a style attributes accordingly.

HTML would be -- <body class="{{ product-id }}">

CSS would be -- product-id : { color: #ccc; } Where product-id would be a dynamic value.

What would be the best method to do this? I want to be able to have this be a selector I could use for various element locations within the page which is why ng-style isn't working for me.

Yasir
  • 879
  • 5
  • 13
  • 31

1 Answers1

0

I think the best approach for what you're looking for is the ng-class directive which allows you to set different dynamic classes based on $scope variables.

You can check out the docs for ng-class here.

Hope that helps you out!

Jhey
  • 1,377
  • 7
  • 10
  • im familiar with ng-class, but how would you then define the style? for ex. product-848483823 would be set to { color: #ccc; } or product-0943094 would also be set to the same style. – Yasir Aug 28 '15 at 01:14
  • Hmm. How many different style combinations are there? and how would the mapping be defined? or where do the style definitions come from? You could define a mapping object in your controller and pass that into the `ng-class` directive attribute possibly if you have a handle on the different styles. Ideally, your styling will be located in CSS files though. – Jhey Aug 28 '15 at 01:20