AngularJS模板不能使用包含连字符JSON [英] AngularJS templates can't use JSON that contains hyphen
本文介绍了AngularJS模板不能使用包含连字符JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
AngularJS模板不能使用包含在关键的连字符JSON。
例如。
我的Json看起来像
{
...
链接:{
XX-测试:{
HREF:'/测试/ XX
}
}
现在,在我的angularjs模板,如果我是指它不工作在href
<一个NG-HREF =/应用/编辑项目= {{item.link.xx-test.href}}?>< / A>
这是无法解决的价值HREF呈现为
/应用/编辑?项目=
它试图
<一个NG-HREF =/应用/编辑项目= {{'item.link.xx-test.href'}}?>< / A>
<一个NG-HREF =/应用/编辑项目= {{item.link.xx \\ -test.href}}?>< / A>
<一个NG-HREF =?/应用/编辑项目= {{项目['link.xx测试'] HREF}}>< / A>
解决方案
的对象密钥需要被引用的:
$ scope.bar = {'XX测试':'富'};
括号表示法应在角前pression使用。
< P> {{条['XX-测试]}}< / P>
您可以选择逃避连字符 \\ -
在角前pression
AngularJS templates can't use JSON that contains hyphen in the key.
e.g.
My Json looks like
{
...
link: {
xx-test:{
href: '/test/xx'
}
}
Now, in my angularjs template if I refer the href it is not working
<a ng-href="/app/edit?item={{item.link.xx-test.href}}"></a>
It is unable to resolve the value href is rendered as /app/edit?item=
It tried
<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>
解决方案
The object key needs to be quoted with:
$scope.bar = {'xx-test':'foo'};
Bracket notation should be used in the angular expression.
<p>{{bar['xx-test']}}</p>
You can optionally escape the hyphen \-
in the angular expression.
这篇关于AngularJS模板不能使用包含连字符JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文