简体   繁体   中英

After changing my List vom ng-repeat to collection-repeat ng-click is not working properly

I had a List like this:

<ion-item ng-repeat="item in items" ng-click="itemClick({{item[0]}})">
    ...
</ion-item>

now I changed it to:

<ion-item collection-repeat="item in items" ng-click="itemClick({{item[0]}})">
    ...
</ion-item>

while having the following code in my controller:

$scope.itemClick = function (index) {
    // index is undefined
};

before making the change from ng-repeat to collection-repeat all works fine. Now I get index as undefined .

Whats wrong here?

EDIT:

Here are my items:

var items = {
    [1, "foo"],
    [2, "bar"], 
    ...
}

{{}} Iterpolation won't work inside ng-click , you can directly mention variable name that will directly gets fetched from their respective variable.

ngClick clearly states that it accepts an expression: http://docs.angularjs.org/api/ng.directive:ngClick

Markup

<ion-item collection-repeat="item in items" ng-click="itemClick(item[0])">
    ...
</ion-item>

try this

<ion-item collection-repeat="item in items" ng-click="itemClick(item[0])">
    ...
</ion-item>

if you want only index value, then try this below

<ion-item collection-repeat="item in items" ng-click="itemClick($index)">
    ...
</ion-item>

{{}}无法在ng-click ,只需del{{}} ,使用itemClick(item[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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