NG-重复只适用于变量{{X}}角括号外面(QUOT;<>")? [英] ng-repeat only works for variable {{ x }} outside of angle brackets ("<>")?

查看:157
本文介绍了NG-重复只适用于变量{{X}}角括号外面(QUOT;<>")?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来angularJS。
当我尝试了 NG-重复,我发现在我的code的一个问题(如下图所示)

 < UL类=下拉菜单中选择角色=菜单中的NG-的init =名称= findDomains()>
<李><风格=光标:指针NG重复=X名称中NG点击=selectDomain({{X}})> {{X}}< / A>&LT ; /李>
< / UL>

的想法是,我有一个下拉菜单(例如,一个名为测试),我的网页上。单击时,它显示的选项和选项都显示为&LT内容;李>< /李> 。所有选项都返回一个按功能设置 findDomains()初始化NG-INIT

在一个特定的选项(在内容<李>< /李> )被选择(例如,一个名为OPT1),在掇文下拉菜单与选项的名称更新(OPT1取代测试)。这是通过函数实现的 selectDomain()

既然是同样的内容得到显示和呼叫 selectDomain(),我把两个{{X}}调用 NG-重复,希望同样的选项显示呼叫 selectDomain()

然而,一切似乎工作正常( findDomains() NG-重复第二 {{X}} 之外< A>< / A> )。但 {{X}} < A>< / A> 不能正常工作。当点击选项,在下拉菜单中的名字不会被更新。

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 function findDomains() and initialized by ng-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 function selectDomain()

Since it is the same content get displayed and call selectDomain(), I put two {{x}} calling ng-repeat, hoping the same option displayed calls the selectDomain().

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 as ng-click="selectDomain('opt1')).

Any guidance?

解决方案

Per Doc

ng-click needs an Expression to evaluate upon click

No need of using interpolation thereng-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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆