javascript - Angular toggle filter in ng-repeat -
i'm trying display data using ng-repeat
. want have filter on displayed data , when click on specific item filter should removed. when click again on specific item, filter should added again.
i've started idea, in view have:
<ion-item class="row" ng-repeat="t in tickets"> <div class="col" ng-click="togglefilter(t.name)">{{t.name}}</div> </ion-item>
in controller:
.controller('ticketctrl', function ($scope, $filter) { $scope.togglefilter = function (name) { name = $filter('getslice')(name); alert(name); } });
when alert name
gives correct filtered item, it's not updating in view. think has child scope of ng-repeat
, don't know how toggling filter.
does has suggestions or solution solve problem?
it's not updating in view, beacause in $scope.togglefilter modifying local variable not binded view, in list angular binded $scope.tickets variable should modify binded variable directly see changes in view, achive using $index iterator variable available when use ngrepeat https://docs.angularjs.org/api/ng/directive/ngrepeat
the result should this:
-view:
<ion-item class="row" ng-repeat="t in tickets"> <div class="col" ng-click="togglefilter(t.name, $index)">{{t.name}}</div> </ion-item>
-controller:
.controller('ticketctrl', function ($scope, $filter) { $scope.togglefilter = function (name, index) { $scope.tickets[index].name = $filter('getslice')(name); alert(name); }
ps off topic: see using ionic framework, if going use ng-repeat in mobile devices performance going better if use collection repeat directive, mobile devices doesn't perform smooth when scroll long lists of elements ng-repeat because de 2 way binding of angular. http://ionicframework.com/docs/api/directive/collectionrepeat/
Comments
Post a Comment