NG-重复只适用于变量{{X}}角括号外面(QUOT;&LT;&GT;&QUOT;)? [英] ng-repeat only works for variable {{ x }} outside of angle brackets ("<>")?
问题描述
我是新来angularJS。
当我尝试了 NG-重复
,我发现在我的code的一个问题(如下图所示)
&LT; UL类=下拉菜单中选择角色=菜单中的NG-的init =名称= findDomains()&GT;
&LT;李&GT;&LT;风格=光标:指针NG重复=X名称中NG点击=selectDomain({{X}})&GT; {{X}}&LT; / A&GT;&LT ; /李&GT;
&LT; / UL&GT;
的想法是,我有一个下拉菜单(例如,一个名为测试),我的网页上。单击时,它显示的选项和选项都显示为&LT内容;李&GT;&LT; /李&GT;
。所有选项都返回一个按功能设置 findDomains()
和初始化NG-INIT
。
在一个特定的选项(在内容&LT;李&GT;&LT; /李&GT;
)被选择(例如,一个名为OPT1),在掇文下拉菜单与选项的名称更新(OPT1取代测试)。这是通过函数实现的 selectDomain()
既然是同样的内容得到显示和呼叫 selectDomain()
,我把两个{{X}}调用 NG-重复
,希望同样的选项显示呼叫 selectDomain()
。
然而,一切似乎工作正常( findDomains()
, NG-重复
第二 {{X}}
之外&LT; A&GT;&LT; / A&GT;
)。但 {{X}}
在&LT; A&GT;&LT; / A&GT;
不能正常工作。当点击选项,在下拉菜单中的名字不会被更新。
但 selectDomain()
功能好,因为它正常工作与纯文本(如 NG-点击=selectDomain(OPT1 )
)。
任何指导?
按照Doc
NG-点击
需要一个防爆pression在点击评价
块引用>无需使用插值存在的
NG-点击
不应该使用{{}}
插补指令,他们对在它里面直接访问范围的变量。NG-点击=selectDomain(X)
I am new to angularJS. As I was trying out the
ng-repeat
, I found a problem in my 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 is that I have a drop-down menu (e.g. with name "test") on my page. When clicked, it displays the selections, and the options are displayed as contents in
<li></li>
. All options are returned as a set by functionfindDomains()
and initialized byng-init
.When a particular option (content in
<li></li>
) is selected (e.g. with name "opt1"), the text of the drop-down menu is updated with the name of the option ("opt1" replaces "test"). This is implemented by functionselectDomain()
Since it is the same content get displayed and call
selectDomain()
, I put two {{x}} callingng-repeat
, hoping the same option displayed calls theselectDomain()
.However, everything else seems working fine (
findDomains()
,ng-repeat
and the second{{x}}
outside<a></a>
). But the{{x}}
inside<a></a>
does not work properly. When options are clicked, the dropdown menu name is not updated.But the
selectDomain()
function is good as it works fine with plain text ( such asng-click="selectDomain('opt1')
).Any guidance?
解决方案Per Doc
ng-click
needs an Expression to evaluate upon clickNo need of using interpolation there
ng-click
should not use{{}}
interpolation directive, they to have direct access to scope variables inside it.ng-click="selectDomain(x)"
这篇关于NG-重复只适用于变量{{X}}角括号外面(QUOT;&LT;&GT;&QUOT;)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!