Search code examples
javascriptember.jshandlebars.js

Ember.js/Handlebars.js bind conditional class property to {{#link-to}} helper


I am trying to add a class to the link attribute but the class name is conditional.

{{#link-to "role" this classNames="isLoading:is-loading" tag="tr" }}
   <td {{ bind-attr class="isLoading:is-loading"}}>{{ name }}</td>
   <td>{{ role }}: {{ isLoading }}</td>
   <td>EDIT</td>
{{/link-to}}

So just like this. But somehow it doesn't work.

Is there another way to do this?


Solution

  • Just use classBinding instead of classNames:

    {{#link-to "role" this classBinding="isLoading:is-loading" tag="tr" }}
       <td {{ bind-attr class="isLoading:is-loading"}}>{{ name }}</td>
       <td>{{ role }}: {{ isLoading }}</td>
       <td>EDIT</td>
    {{/link-to}}