How do you update ng-model from view in this case?
I am having a problem updating my ng-model. Sorry if this with errors or I am doing something wrong! I am pretty new to web development!
My HTML code looks something like this:
<div id="loadedCart" ng-show="ifLoadCart">
<div ng-repeat="book in cartbooks" repeat-finish>
<br>
<!--<img src="book.path" alt="img of book"></img>-->
<h6 ng-click="deleteBook(book.id)">{{book.name}}</h6>
<h6>{{book.authors}}</h6>
<h6>{{book.price}}</h6>
<h6>{{book.qboy}}</h6>
<input ng-model="thisoneshould" type="number" min="0" required>
<input type="submit" ng-click="changeQuant(book.id)" value="Update quantity">
<br><br><br>
</div>
<div><button ng-click="checkout()">Checkout</button></div>
</div>
And my code in the controller looks something like this:
$scope.thisoneshould = 0;
//other variables that are defined...
$scope.changeQuant = function(x){
$scope.updateCart(x);
}
$scope.updateCart = function(x){
$scope.showLoginErrorMsg = false;
$scope.needToLogin = false;
$scope.showLoginErrorMsg = false;
$scope.ifhomepage = false;
$scope.ifSuccessful = false;
$scope.ifbookpage = false;
$scope.ifcheckpage = false;
$scope.ifShowQuantity = false;
$scope.additionSuccess = false;
$scope.ifLoadCart = true;
console.log(x);
console.log($scope.thisoneshould);
//$scope.cartbooks = [];
if ($scope.thisoneshould!=0)
{
console.log($scope.thisoneshould);
$http.put('updatecart',{'bookId': x, 'quantity': $scope.thisoneshould}).then(function(response){
$scope.itemsInCart = response.data;
});
}
else {
$http.delete('deletefromcart/'+x).then(function(response){
$scope.itemsInCart = response.data;
});
}
}
Can someone tell me what seems to be the problem with my code, why it is wrong and how do I fix it?