AngularJS 模板不能使用键中包含连字符的 JSON。
e.g.
我的 Json 看起来像
{
...
link: {
xx-test:{
href: '/test/xx'
}
}
现在,在我的 angularjs 模板中,如果我引用 href 它就不起作用
<a ng-href="/app/edit?item={{item.link.xx-test.href}}"></a>
无法解析值 href 呈现为
/应用程序/编辑?项目=
它尝试过
<a ng-href="/app/edit?item={{'item.link.xx-test.href'}}"></a>
<a ng-href="/app/edit?item={{item.link.xx\-test.href}}"></a>
<a ng-href="/app/edit?item={{item.['link.xx-test'].href}}"></a>
对象键需要用以下引号引起来:
$scope.bar = {'xx-test':'foo'};
角度表达式中应使用括号表示法。
<p>{{bar['xx-test']}}</p>
您可以选择转义连字符\-
在角度表达式中。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)