Angularjs 语法危险:标记';}';意外,在表达式[yourSelectRadio={item.Polarisation}的第35列应为[:]
我的代码:Angularjs 语法危险:标记';}';意外,在表达式[yourSelectRadio={item.Polarisation}的第35列应为[:],angularjs,angularjs-ng-init,Angularjs,Angularjs Ng Init,我的代码: 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%20unexp
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
垂直的
水平的
为什么会发生此错误?{}是一个对象,您需要为该项设置一个键
<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>
或
编辑:
ng init
函数需要一个对象。JSON定义为
{“key”:“value”}
不是{[OBJECT]}
假设item.Polarisation~={“thing”:“one”,“otherthing”:2}
有两种方法可以修复错误
直接指派
yourSelectRadio=item.Polarisation // if it is an object
-或
封装
<div class="btn-group" ng-init="yourSelectRadio=item.Polarisation">
使用angular.toJson(对象):
垂直的
水平的
yourSelectRadio={item.Polarisation}
不是有效的javascript。。。。使它有效。考虑到无效的javascript,我不知道您的意图是什么,因此我无法建议如何“修复它”。谢谢@KevinB,引号是为了避免他将键与他引用的item对象混淆。这个答案毫无意义。你能写出一个更完整的例子吗?
<div class="btn-group" ng-init="yourSelectRadio=item.Polarisation">
<div class="btn-group" ng-init="yourSelectRadio={'radioItem': item.Polarisation}">
<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>