Emberjs how to bind-attr an id

2019-09-04 09:58发布

问题:

I want to use ember properties to toggle the visibility of a div by calling it's dynamic id, however even though I can do something similar by calling classes, I cannot do the same for id's.

For example: {{bind-attr class=":class1 controller.controllerProperty:class2"}} works fine. I can toggle the controllerProperty from an action in my controller.

You would think the same concept would apply to id's. However {{bind-attr id=":staticId controllerProperty:id{{dynamicIdNumber}}"}} makes the id's disappear all together!

Why is this happening and what is the correct method to be doing this sort of this? I would like to avoid work-around solutions as much as possible.

回答1:

Binding to classes is a special case in Ember as described in here Binding the other attributes to properties is described here