Using the already-overused to-do app example, let’s say I want an element with a “todo” class (static) and an “is-done” class (dynamic):
<div {{bindAttr class="todo isDone"}}>
Other stuff in here
</div>
In this case, “isDone” and “todo” are both expected to be properties on my view object, which is what I want for “isDone”, but not for “todo”. I’m currently working around this by adding a “todo” property on my view that is equal to a static “todo” string. Is there any way to have a static class attribute when using bindAttr?
Fiddle example: http://jsfiddle.net/nes4H/4/
EDIT:
We’ve fixed this in Ember!
On a build from master, or after 0.9.6 is released, you can now do:
<div {{bindAttr class="App.foo:a-bound-class :a-static-class"}}></div>Previous answer:
You unfortunately can’t have both static and dynamic class names when using
bindAttr.I suggest using one or more computed properties on your view to output both static and dynamic class names.
Supporting both static and dynamic class names would be very nice, but the way
bindAttrcurrently works, it’s not possible.bindAttrdoesn’t know anything about the element it’s being attached to during template compilation.