javascript - ng-repeat only works for variable {{ x }} outside of angle brackets ("<>")? -


i new angularjs. trying out ng-repeat, found problem in code (shown below)

<ul class="dropdown-menu" role="menu" ng-init="names=finddomains()"> <li><a style="cursor:pointer" ng-repeat="x in names" ng-click="selectdomain({{ x }})">{{ x }}</a></li> </ul> 

the idea have drop-down menu (e.g. name "test") on page. when clicked, displays selections, , options displayed contents in <li></li>. options returned set function finddomains() , initialized ng-init.

when particular option (content in <li></li>) selected (e.g. name "opt1"), text of drop-down menu updated name of option ("opt1" replaces "test"). implemented function selectdomain()

since same content displayed , call selectdomain(), put 2 {{x}} calling ng-repeat, hoping same option displayed calls selectdomain().

however, else seems working fine (finddomains(), ng-repeat , second {{x}} outside <a></a>). {{x}} inside <a></a> not work properly. when options clicked, dropdown menu name not updated.

but selectdomain() function works fine plain text ( such ng-click="selectdomain('opt1')).

any guidance?

per doc

ng-click needs expression evaluate upon click

no need of using interpolation thereng-click should not use {{}} interpolation directive, have direct access scope variables inside it.

ng-click="selectdomain(x)" 

Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

wso2esb - How to concatenate JSON array values in WSO2 ESB? -