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>
You cannot declare variable with the character '-'. The json file might be a typo so I would probably just modify the json file property to read uploadTime and go from there. I dare say that most json files you will be getting wont have hyphen in the names so you shouldn't come across it again.
In Angular, a template is a chunk of HTML.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With