Syntax danger: Token '}' is unexpected, expecting [:] at column 35 of the expression [yourSelectRadio={item.Polarisation}]

Footabll.My.Life picture Footabll.My.Life · Oct 8, 2014 · Viewed 7.3k times · Source
error : Error: [$parse:syntax] Syntax danger: Token '}' is unexpected, expecting [:] at column 35 of the expression [yourSelectRadio={item.Polarisation}] starting at [}].
http://errors.angularjs.org/1.2.21/$parse/syntax?p0=%7D&p1=is%20unexpected%2C%20expecting%20%5B%3A%5D&p2=35&p3=yourSelectRadio%3D%7Bitem.Polarisation%7D&p4=%7D

my code:

<div class="btn-group" ng-init="yourSelectRadio={item.Polarisation}"> 
<label class="btn btn-success ng-pristine ng-valid" ng-model="yourSelectRadio" btn-radio="'Vertical'">Vertical</label> 
<label class="btn btn-success ng-pristine ng-valid" ng-model="yourSelectRadio" btn-radio="'Horizontal'">Horizontal</label>
</div>

Why does this error occur?

Answer

corn3lius picture corn3lius · Oct 8, 2014

{} is an object you need a key for the item

{ 'key' : item.Polarisation } ? 

or

yourSelectRadio=item.Polarisation // if it is an object 

edit :

the ng-init function requires an object. JSON is defined as { "key" : "value" } not { [OBJECT] }

assuming item.Polarisation ~= { "thing" : "one", "otherthing" : 2 }

There are two ways to fix the error.

Direct assignment

<div class="btn-group" ng-init="yourSelectRadio=item.Polarisation">  

-or-

Encapsulation

<div class="btn-group" ng-init="yourSelectRadio={'radioItem': item.Polarisation}">