我正在学习angularjs。我已经介绍了一个问题,当我点击ng-click时,ng-model没有更新。我的代码如下,
<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>
&#13;
答案 0 :(得分:1)
试试这个
<button type="button" ng-click="product.quantity = product.quantity+1">+</button>
<button type="button" ng-click="product.quantity = product.quantity -1">-</button>
答案 1 :(得分:1)
试试这个
var jimApp = angular.module("mainApp", []);
jimApp.controller('mainCtrl', function($scope){
});
&#13;
<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>
&#13;