Ng-click仅适用于双击

时间:2017-03-23 10:08:41

标签: html angularjs ionic-framework

当我在此离子删除图标上按两次时,只有它会删除项目。所以请纠正我。提前致谢。

这是我的div调用函数“removeFromWishList(obj,$ index)”

       <div class="col" ng-click="removeFromWishList(obj,$index)" > 
          <i class="icon ion-ios-trash-outline font_20px"  ></i>
        </div>

这是我在控制器中的removeFromWishList(obj,$ index)函数

$scope.removeFromWishList = function (obj, index) {
  if ($scope.wishlistItems.indexOf(obj.id) > -1) {
    angular.forEach($scope.wishlistItems, function (val, key) {
      if (val == obj.id) {
        $scope.wishlistItems.splice(key, 1);
        Wishservice.remwishid(index);


      }
      $state.go($state.current, {}, {reload: true});
    });
  } else {
    $scope.wishlistItems.push(obj.id);
  }
};

1 个答案:

答案 0 :(得分:0)

请尝试以下代码:

$scope.removeFromWishList = function(obj, index) {
    var index = $scope.wishlistItems.indexOf(obj.id);
    if (index > -1) {
        $scope.wishlistItems.splice(index, 1);
        $state.go($state.current, {}, {reload: true}); // not sure why this is needed
    } else {
        $scope.wishlistItems.push(obj.id);
    }
};
相关问题