Dmitro
Dmitro

Reputation: 1549

How to bind value to attribute if this value will changes in each?

I try to do it like that:

{{#each item in controller.records}}
  <li {{bind-attr class=":message (compare controller.currentUser.id item.user_id)::mes-self" >
   .....
  </li>
{{/each}}

And mes-self didn't add to class attribute. Is there possibility to do that?

Upvotes: 0

Views: 47

Answers (1)

Daniel
Daniel

Reputation: 18672

I see 3 problems in your code:

  1. You're using old {{each in}} helper. It's deprecated now.
  2. You're using deprecated {{bind-attr}} helper.
  3. You're using shorthand helper with {{bind-attr}} + :: and that's unlikely to work.

Instead, please try:

{{#each controller.records key='id' as |item|}}
  <li class="message {{if (compare controller.currentUser.id item.user_id) '' 'mes-self'}}">
   .....
  </li>
{{/each}}

I'm assuming you're using Ember v1.13+ and {{compare}} expression was declared(you've created this helper) and it returns true if passed values are the same.

Upvotes: 1

Related Questions