javascript - How can I call a function with user selected data? -
i'm having contacts array holding list of emails. generate div's using ng-repeat
when user clicks on particular div call ng-click="foo($index)"
var contacts=[somemail]; var userselectedcontact[]; $scope.foo=function(row) { userselectedcontact.push(contacts[row]); }
the problem when add "|filter"
in ng-repeat
search , select particular contact.
since filter creates array after filtering: when ever user selects contact foo($index)
called, , adding other contact not selected user.
i can understand since using $index
different index in original contacts array before filter.
so have stop using either filter (or) index find user selected contact. should do? there other way?
how can call function user selected data ng-click="foo(someemail)"
?
you can pass whole ng-repeat
item ng-click
function
<div ng-repeat="item in items" ng-click="myfunction(item)"></div>
and in controller
$scope.myfunction(item) { console.log(item.name); //or whatever want item }
Comments
Post a Comment