How Do I disable a clicked button in AngularJS?

80 views
Skip to first unread message

Kapil Soni

unread,
Jul 9, 2017, 8:08:45 AM7/9/17
to Angular and AngularJS discussion

I have create a shopping website in which user click on the addToCart button product is add into the cart and i have to disabled a clicked button but in my case all the button is disabled how to fix this issue?
This is my HTML Code:-
<a class="w3-btn w3-red" ng-model="item.cart" 
        ng-click="isDisabled || addProductInCart($index,list)"
        ng-disabled="isDisabled">Add To Cart
    </a>
//Here our controller code:-
 	/**
	 * @Summary:addProductInCart , to add prodduct in cart.
	 * @param:   index, items
	 * @return:  NA
	 * @Description: 
	 */
	 $scope.item                 = {};
	 $scope.prouctInCartList     = [];
	 $scope.totalAmountDisplay   = 0;
	 $scope.countProducts        = 0;
	$scope.isDisabled = false;
	
 	$scope.addProductInCart = function(index, item) {
 		$scope.isDisabled = true;
 		var data = {
			index :index,
			cart : item 			
 		}
 		$rootScope.prouctInCartList.push(data);}

Zlatko Đurić

unread,
Jul 10, 2017, 2:00:39 AM7/10/17
to Angular and AngularJS discussion
Maybe have is Disabled being a map instead?
E.g.directive would be:
ng-disabled="isDisabled[$index]"

And than your controller sets that:

addToCart(index, ...rest) {
...
this.isDisabled[index] = true;
...
}

(Or whatever the method names, typing on a phone here).

Reply all
Reply to author
Forward
0 new messages