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?

4
  • Why don't you just <div ng-init="myvar = obj.rating" />? Commented Aug 13, 2013 at 16:03
  • Sorry this was not expressed correctly, edited now the post. Commented Aug 13, 2013 at 16:06
  • Hm, interesting. I did the plunker and there it works. I guess I have to review my code... Commented Aug 13, 2013 at 16:31
  • Plunker helped me accidentally finding the reason/solution - they provide the most recent (not stable) version of Angular and there it works. Commented Aug 13, 2013 at 19:12

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

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.

3 Comments

Not true - I just could do it with Plunker: plnkr.co/edit/kgsKs6Boe7rcOLCp0abH?p=preview
It seems they changed this. You are probably right concerning the current stable version. With 1.1.5 it works.
@lxx Thanks. I am not quite following the unstable version, but it is good to know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.