简体   繁体   中英

Angular issue with data -ng-init

i have a init function for rate functionality

This is working fine

<div data-ng-init="rating = 5">

But rating values are dynamic ,

<div data-ng-init="rating = {{ datasourcelist.rating }}">

But this is throwing error

(Error: Syntax Error: Token 'datasourcelist.rating' is unexpected, expecting [:] at column 13 of the expression [rating = {{ datasourcelist.rating }}] starting at [datasourcelist.rating }}].)

Please help ,

When you use angular directives you do not need to put double brackets so

<div data-ng-init="rating = datasourcelist.rating">

should work.

{{ .. }} is called interpolation , which will transform the model value to a string. It returns a string .

data-ng-init="rating = {{ datasourcelist.rating }}" is just like assigning a string to the model object rating .

What you need is object assignment:

data-ng-init="rating = datasourcelist.rating"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM