2016-05-28 5 views
0

Eigentlich lerne ich angularjs. Ich habe ein Problem eingeführt, dass wenn ich NG-klicke, NG-Modell nicht aktualisiert wird. Mein Code ist wie folgt,ng-model aktualisiert sich nicht in Angularjs

<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>

+0

'ng-click' erwartet einen Ausdruck, keinen generischen JavaScript-Code. Ihr Ereignisprotokoll zeigt sicher 'Fehler: [$ parse: ueoe] Unerwartetes Ende des Ausdrucks: product.quantity ++' https://docs.angularjs.org/error/$parse/ueoe?p0=product.quantity%2B%2B . – Claies

Antwort

1

versuchen, wie diese

<button type="button" ng-click="product.quantity = product.quantity+1">+</button> 
<button type="button" ng-click="product.quantity = product.quantity -1">-</button> 
+0

Funktioniert gut. Vielen Dank .. – Rubel

+0

Sie sind willkommen. Ich war froh, dir zu helfen :) –

1

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>