简体   繁体   English

ng-Click不在ng-repeat中使用{{$ index}}

[英]ng-Click not working with {{$index}} inside ng-repeat

this seems like a simple problem but it has taken hours of mine . 这似乎是一个简单的问题,但它花了我几个小时。

I've the following code. 我有以下代码。

            <div class="row grid" id="draftRow{{$index}}" ng-repeat="draft in drafts">
            <div class="col-md-7 cell" ng-bind="draft.getTitle()"></div>
            <div class="col-md-2 cell center" ng-bind="draft.getUserName()"></div>
            <div class="col-md-2 cell center" ng-bind="draft.getDate()"></div>
            <div class="col-md-1 cell center" >
                <span class="gridbutton" ng-click="editPost(draft.getPostID())">edit</span>
                |
                <span class="gridbutton" ng-click="deletePost(draft.getPostID(),'{{$index}}')">delete</span>
            </div>
            </div>

The deletePost function is not being called onclick although I can see deletePost(draft.getPostID(),'0') written on browser inspect element. 虽然我可以看到在浏览器检查元素上写的deletePost(draft.getPostID(),'0')但是没有调用deletePost函数。 What is the problem here can anyone point out ? 有人指出这里有什么问题? If I remove the second parameter of the deletePost function everything runs fine . 如果我删除deletePost函数的第二个参数一切正常。

I've also tried $parent.$index , that calls the function but doesn't output the rowIndex on inspect element. 我也试过$parent.$index ,它调用函数但不在inspect元素上输出rowIndex

正如我在评论中所说:不使用{{...}}进行解释,只需使用变量本身: deletePost(draft.getPostID(), $index)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM