簡體   English   中英

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

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

這似乎是一個簡單的問題,但它花了我幾個小時。

我有以下代碼。

            <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>

雖然我可以看到在瀏覽器檢查元素上寫的deletePost(draft.getPostID(),'0')但是沒有調用deletePost函數。 有人指出這里有什么問題? 如果我刪除deletePost函數的第二個參數一切正常。

我也試過$parent.$index ,它調用函數但不在inspect元素上輸出rowIndex

正如我在評論中所說:不使用{{...}}進行解釋,只需使用變量本身: deletePost(draft.getPostID(), $index)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM