Reputation: 71
Acutally I am learning angularjs. I've introduced a problem is that when I click ng-click, ng-model is not updating. My code is as follows,
<div ng-repeat="product in cart">
<input type="number" ng-model="product.quantity" ng-required class="input-sm">
<button class="btn btn-xs" type="button" ng-click="product.quantity++">+</button>
<button class="btn btn-xs" type="button" ng-click="product.quantity--">-</button>
</div>
Upvotes: 0
Views: 47
Reputation: 5273
Try This
var jimApp = angular.module("mainApp", []);
jimApp.controller('mainCtrl', function($scope){
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="mainApp">
<div ng-controller="mainCtrl">
<input type="number" ng-model="product.quantity" ng-required class="input-sm">
<button class="btn btn-xs" type="button" ng-click="product.quantity = (product.quantity +1)">+</button>
<button class="btn btn-xs" type="button" ng-click="product.quantity = (product.quantity -1)">-</button>
</div>
</div>
Upvotes: 1
Reputation: 17289
try like this
<button type="button" ng-click="product.quantity = product.quantity+1">+</button>
<button type="button" ng-click="product.quantity = product.quantity -1">-</button>
Upvotes: 1