AngularJS NG-点击不使用{{$指数}}调用 [英] AngularJS ng-click not invoked with {{$index}} used

查看:150
本文介绍了AngularJS NG-点击不使用{{$指数}}调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某种原因AngularJS不会触发关闭事件时,{{$指数}}在NG-点击使用。

For some reason AngularJS does not fire off the event when {{$index}} is used in ng-click.

我的HTML:

<div ng-controller="Ctrl">
  <ul>
    <li ng-repeat="foo in foos">
     <label>{{foo.name}}</label>
     <a href="#" ng-click="remove({{$index}})">X (doesnt work)</a>
     <a href="#" ng-click="remove(0)">Remove first element (works)</a>
    </li>
  </ul>
 </div>

的jsfiddle: http://jsfiddle.net/Lcasg/3/

任何人知道如何解决这一问题?谢谢

Anyone knows how to fix this? Thanks

推荐答案

在NG-点击属性的值被评为角前pression,所以只需使用删除($指数)

The value of the ng-click attribute is evaluated as an angular expression, so simply use remove($index).

这篇关于AngularJS NG-点击不使用{{$指数}}调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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