如何防止在AngularJS中多次点击锚标记?

时间:2017-10-12 13:01:22

标签: javascript angularjs

我已经创建了共享功能,但是



//HERE WE CREATE THE CONTOLLER FOR SHARING
$scope.selectedSharedBuyerKeyList     = [];
$scope.selectedSharedBuyerObjectList  = [];
$scope.productObjectForShareModal     = [];

$scope.getConnectedSharedUser         = function(product) {
$scope.productObjectForShareModal = product;
var data = {
  productKeyId : $scope.productObjectForShareModal.keyId
}

//Call the getSharedUserList function for get the detail of the shared connectedUsers
SellerDashboardService.getSharedUserList(function(response) {				
    if(response != null) {
      if (response.data.isProduct) {
        $scope.selectedSharedBuyerKeyList = response.data.sellerProductsDto;

        // Obtaining user object..
        $scope.selectedSharedBuyerObjectList = [];
        for(var selectedSharedBuyerKey of $scope.selectedSharedBuyerKeyList) {
          var data = selectedSharedBuyerKey;
          //call the getBuyerInShared for get the list of the objects 
          SellerDashboardService.getBuyerInShared(function(response) {
            if(response != null) {
              if (response.data.isbuyer) {
                var buyerObject = response.data.isbuyer;
                $scope.selectedSharedBuyerObjectList.push(buyerObject);
              }
            }
          },data);
        }
      }
    }
},data);
}

<a href="#" class="fa fa fa-group btn btn-xs pull-left bg-color-d4"
    data-toggle="modal" data-target="#groupModal" 
  ng-click="getConnectedSharedUser(productDBList)">
</a>
&#13;
&#13;
&#13;

多次点击a标签后重复

列表,并且一次又一次地重复用户列表。那么告诉我如何解决重复问题?

2 个答案:

答案 0 :(得分:1)

试试这个

$scope.selectedSharedBuyerObjectList  = [];
$scope.productObjectForShareModal     = [];

$scope.cliked=false ///set click to false



$scope.getConnectedSharedUser         = function(product) {
$scope.productObjectForShareModal = product;
var data = {
  productKeyId : $scope.productObjectForShareModal.keyId
}

//Call the getSharedUserList function for get the detail of the shared connectedUsers
SellerDashboardService.getSharedUserList(function(response) {               
$scope.clicked =true;  ///set it back to true
    if(response != null) {
      if (response.data.isProduct) {
        $scope.selectedSharedBuyerKeyList = response.data.sellerProductsDto;

        // Obtaining user object..
        $scope.selectedSharedBuyerObjectList = [];
        for(var selectedSharedBuyerKey of $scope.selectedSharedBuyerKeyList) {
          var data = selectedSharedBuyerKey;
          //call the getBuyerInShared for get the list of the objects 
          SellerDashboardService.getBuyerInShared(function(response) {
            if(response != null) {
              if (response.data.isbuyer) {
                var buyerObject = response.data.isbuyer;
                $scope.selectedSharedBuyerObjectList.push(buyerObject);
              }
            }
          },data);
        }
      }
    }
},data);
}



<a href="#" class="fa fa fa-group btn btn-xs pull-left bg-color-d4"
    data-toggle="modal" ng-disabled="cliked" data-target="#groupModal" 
  ng-click="getConnectedSharedUser(productDBList)">
</a>

答案 1 :(得分:1)

我在角度2中所做的是我在第一次点击时禁用了按钮。

E.g。

<button (click)="someFunction()" [disabled]="disableButton"></button>
someFunction() {
      disableButton = true;
} 

注意:语法在您的情况下会有所不同,但逻辑会相同。 我希望这会有所帮助。