Kim Sean Kim Sean - 1 year ago 82
AngularJS Question

angularJs ng-click is not working inside the ng-if function

<div ng-if="quantity > 0">
<button ng-click="quantity = quantity-1">-</button>

Above is my code. i dont know why the ng-click doesnt work when it shows up. anyone can give me advise? thanks.

Answer Source

Try this it will work :

<div ng-controller="MyCtrl">
  <div ng-show="quantity > 0">
    <button ng-click="quantity = quantity-1">-</button>

app.controller('MyCtrl', function($scope) {
  $scope.quantity = 6;

Working fiddle :

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download