I'm basing the issue on the following codepen: http://codepen.io/ionic/pen/JsHjf
It uses: <ion-reorder-button class="ion-navicon" on-reoder="moveItem(item, fromIndex, toIndex)"></ion-reorder-button>
and it is working just fine.
I want to move whole <ion-item>
into a directive. Here is my plnkr: http://plnkr.co/edit/w61yqfuCypliugToUD3E?p=preview and some essential code parts:
directive("myitem", function() {
return {
restrict : "E",
scope : {
item : "=",
onItemDelete : "&",
moveItem : "&"
},
templateUrl : "MyItemTemplate"
}
})
<ion-item>
{{ item.id }}
<ion-delete-button class="ion-minus-circled" ng-click="onItemDelete({'item': item})"></ion-delete-button>
<ion-reorder-button class="ion-navicon" on-reorder="moveItem({'item' : item, 'fromIndex' : fromIndex, 'toIndex' : toIndex})"></ion-reorder-button>
</ion-item>
I know how to pass multiple parameters thanks to that question: AngularJS directive binding a function with multiple arguments
However the fromIndex and toIndex are not propagated
$scope.moveItem = function(item, fromIndex, toIndex) {
console.log("moveItem: ", item, fromIndex, toIndex);
console.log("unfortunately, the fromIndex and toIndex are undefined");
$scope.items.splice(fromIndex, 1);
$scope.items.splice(toIndex, 0, item);
};
I tried looking into the source, moving up to the call stack but I cannot spot any obvious blunders there.
So yes, I would really like to take benefit of reorder-able list while keeping it into a separate directive.
In this case, the name of the parameter you're passing matters. You want to have:
on-reorder="moveItem(item, $fromIndex, $toIndex)"