angularjs - How to delete the item from the list -


im creating app using ionic , angularjs. in app developing have used swipe option ionic delete specific coupon main-list. problem problem face here is, im able delete description of selected coupon, not able delete/remove coupon main-list. have use $rootscope have declared json array. have declare $scope.item selected coupon , details being pushed, in-order display description of each selected coupons. i'm going wrong somewhere in code please me right. thank you.

html:

<ion-list>         <ion-item ng-click="select_item(coupons)" ng-repeat="coupons in couponlist" ng-model="coupons.selected">             {{coupons.coupontitle}} <br>             <ion-option-button ng-click="editcoupons(coupons)">edit</ion-option-button>             <ion-option-button class="button-assertive" ng-click="deleteselected(coupons)">delete</ion-option-button>         </ion-item>     </ion-list>     <hr>     <div style="text-align:center">         <div ng-repeat="item in items">             coupon offer: {{item.data.description}}<br> valid from: {{item.data.fromldate}}             <br> valid till: {{item.data.todate}} </div> 

controller:

$scope.items = [];       $rootscope.couponlist = [{ coupontitle: "purchase worth $100", data: {description: "$50 off", fromldate: "2016-09-09", todate: "2016-09-18"}},       {coupontitle: "purchase worth $300",  data:{description: "$75 off", fromldate: "2016-11-09", todate: "2016-10-19"}},       { coupontitle: "purchase worth $500",data:{description: "$95 off", fromldate: "2016-09-10", todate: "2016-09-30"}}];        $scope.select_item = function (key) {         $scope.items.push(key);        }   $scope.deleteselected = function () {            $scope.items.splice($scope.items.indexof());     } 

as suggested in 1 answer can use $index mechanism remove object array.

you have delete both items array , rootscope array

view:

<ion-option-button class="button-assertive" ng-click="deleteselected($index,coupons)">delete</ion-option-button> 

controller:

 $scope.deleteselected = function (index,coupons) {      $rootscope.couponlist.splice(index,1);       var to_delete = $scope.items.find(find_data)       function find_data(items) {          return items.coupontitle === coupons.coupontitle;      }       var index = $scope.items.indexof(to_delete);       $scope.items.splice(index,1)    } 

here partial implemented fiddle

you should delete both items array , also, couponlist remove in ng-repeat


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - IE9 error '$'is not defined -