0

I can't use an expression with form object.property in certain situations:

<raty score="{{obj.rating}}"></raty>

Or:

<div ng-init="myvar=obj.rating" />
<raty score="{{myvar}}"></raty>

In both cases JS complains: "Error: Syntax Error: Token 'obj.rating' is unexpected, expecting [:] at column 3 of the expression [{{obj.rating}}] starting at [obj.rating}}]. " or "Error: Syntax Error: Token 'myvar' is unexpected, expecting [:] at column 3 of the expression [{{myvar}}] starting at [myvar}}].".

The background story (for what I need this) is in this thread.

I have already tried many things, read a few threads like: Optional expression attribute in AngularJS directive or How to get evaluated attributes inside a custom directive

But it doesn't seem to address this specific problem of calling object.property. I need it this way because I'm iterating through a JSON document.

Any ideas?

Community
  • 1
  • 1
User
  • 31,811
  • 40
  • 131
  • 232

2 Answers2

0

Interpolation doesn't work in the attributes in the tags like <raty score="{{obj.rating}}"></raty>. One possible way to do it is creating a template in the directive and then apply the directive to the HTML control.

Updated:

With 1.1.5 it works.

zs2020
  • 53,766
  • 29
  • 154
  • 219
  • Not true - I just could do it with Plunker: http://plnkr.co/edit/kgsKs6Boe7rcOLCp0abH?p=preview – User Aug 13 '13 at 18:42
  • It seems they changed this. You are probably right concerning the current stable version. With 1.1.5 it works. – User Aug 13 '13 at 19:10
  • @lxx Thanks. I am not quite following the unstable version, but it is good to know. – zs2020 Aug 13 '13 at 19:15
0

This works in AngularJS (not stable) version 1.1.5. I was working with the currently stable version 1.0.7.

User
  • 31,811
  • 40
  • 131
  • 232