我在HTML文件中的以下内容:AngularJS NG-模型转换对象为字符串
<td style="width: 200px;">
<span ng-repeat="list in listGroups">
<label for="{{ list.description }}" />{{ list.description }}</label>
<input ng-model="$parent.listGroup" id="listGroup-{{ list.value }}" name="listGroups" value="{{ list }}" type="radio" />
</span>
</td>
的listGroups包含:
[
{
"description": "New by Territory",
"group": "product",
"type": "new"
},
{
"description": "New by Genre",
"group": "genre",
"type": "new"
},
{
"description": "Charts by Territory",
"group": "product",
"type": "chart"
},
{
"description": "Charts by Genre",
"group": "genre",
"type": "chart"
}
]
当我点击纳克一个单选按钮listGroup(组-model)变为,例如:
{"description":"New by Genre","group":"genre","type":"new"}
当我看到有typeof $scope.listGroup
listgroup,我看到它是一个现在串!
因此,我无法在HTML页面的其他部分访问其他绑定中的属性。
在这种情况下,我想ng-show="listGroup.group == 'genre'"
这里发生了什么,更重要的是,我怎么让它做我想做的事情,这是保持对象作为一个对象?
感谢所有
戴夫
此外,不要使用'$ parent.',它可以在未来给你带来问题。 – bmleite 2013-02-12 14:04:24