Is there a built in way to have a dynamic
class specified for a custom element?There's two places in the documentation that refers to this approach:
1. reflectToAttribute, which can be specified like this:
properties: {
class: {
type: String,
computed: 'computeClass(var1, var2)',
reflectToAttribute: true
}
}
However this issues the following error:
Uncaught TypeError: Cannot read property '_xScopeSelector' of undefinedPolymer.Base._addFeature._scopeElementClass @ x-styling.html:265Polymer.Base._addFeature.serializeValueToAttribute @ x-styling.html:279Polymer.Base._addFeature.reflectPropertyToAttribute @ attributes.html:107Polymer.Base.extend.reflectEffect @ effects.html:33
2. Another approach that I tried was using hostAttributes. This one works with static values, but doesn't work with binding or computed values, like:
hostAttributes:{
class: 'computeClass(var1, var2)'
}
The workaround now is to have a div as the parent of all elements in the template, and have a class property attached to it with data binding.
But is there a way to dynamically change an element's class?