angularjs - ng-repeat | filter, How do I use the new this.$index or key from JavaScript -
when filter ng-repeat, this.$index , key both change reflect objects position in filtered array.
the problem see unfiltered array javascript this.$index , key giving unexpected result.
html:
<section ng-repeat="( key, place ) in places | filter: ({ name : placename })" > <button ng-click='myfunc( this.$index )'>pick {{place.name}}</button> <!-- same issue key --> <section> javascript:
myfunc(key){ console.log( $scope.places[key] ); } i can loop on array , find $id or own identifier seems wasteful when need index can pass on function looking @ unfiltered array.
thanks.
instead of passing in index, pass in actual object:
<section ng-repeat="( key, place ) in places | filter: ({ name : placename })" > <button ng-click='myfunc( place )'>pick {{place.name}}</button> <!-- same issue key --> <section> then in javascript
$scope.myfunc(place){ console.log( place ); } this make testing myfunc method easier since supplying object in acting upon.
Comments
Post a Comment