0

I am building an app in which user have to addtocart using increment/decrement button. As value=0 i want decrement button to be disabled. I used ng-disabled as such:

 <div class="plus-minus">
     <div class="dec qtybutton" ng-click="pro.countVal = (pro.countVal-1)"
          ng-disabled="pro.countVal === 1">-</div> 
     <input type="text" name="qtybutton" class="cart-plus-minus-box"
            required ng-model="pro.countVal" >
     <div class="inc qtybutton"
          ng-click="pro.countVal=(pro.countVal+1)">+</div>
     </div>

But its not working. How can i implement such?

enter image description here

1 Answer 1

1

ng-disabled doesn't affect div elements. Generally it is more clear to put functionality into the controller using functions. There you can add validation checks etc. :

<div class="plus-minus">
    <div class="dec qtybutton" ng-click="minus()">-</div>
    <input type="text" name="qtybutton" class="cart-plus-minus-box" required ng-model="pro.countVal">
    <div class="inc qtybutton" ng-click="plus()">+</div>
</div>
$scope.pro = {};
$scope.pro.countVal = 0;

$scope.minus = function() {
    if ($scope.pro.countVal === 0) return;
    $scope.pro.countVal--;
}

$scope.plus = function() {
    $scope.pro.countVal++;
}
Sign up to request clarification or add additional context in comments.

7 Comments

Its not working as : Cannot read property 'countVal' of undefined ERROR
Its working but as i add in my app ;function +/- is working but value is not shown in given input box though ng-model = same. What might be the cause of that sir?
Hi, without a fiddle or something I can't say that is wrong with your code !
I have used ng-repeat to repeat the elements and pro comes from ng-repeat;i cant seem to work it out;
Can you create a jsfiddle with a reproducable example? I cannot help without seeing the code!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.