2
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?

Jerodev
  • 32,252
  • 11
  • 87
  • 108
Footabll.My.Life
  • 155
  • 2
  • 4
  • 13
  • `yourSelectRadio={item.Polarisation}` isn't valid javascript. – Kevin B Oct 08 '14 at 14:29
  • ... make it valid. Given that invalid javascript, I have no idea what your intention was, therefore i can't suggest how to "fix it" – Kevin B Oct 08 '14 at 14:32

2 Answers2

3

{} 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}"> 
corn3lius
  • 4,857
  • 2
  • 31
  • 36
0

use angular.toJson(Object) :

<div class="btn-group" ng-init="yourSelectRadio=angular.toJson(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>
HamidReza
  • 1,726
  • 20
  • 15