AngularJS templates can't use JSON that contains hyphen -


angularjs templates can't use json contains hyphen in key.

e.g.

my json looks

{    ...    link: {        xx-test:{             href: '/test/xx'          } } 

now, in angularjs template if refer href not working

<a ng-href="/app/edit?item={{item.link.xx-test.href}}"></a> 

it unable resolve value href rendered /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 quoted with:

$scope.bar = {'xx-test':'foo'}; 

bracket notation should used in angular expression.

<p>{{bar['xx-test']}}</p> 

you can optionally escape hyphen \- in angular expression.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -