I am new to AngulatJs(1.4). My Angular script creates two buttons(plus&minus)
so that users can increase/decrease product's quantity. It works fine. However, when I click update, it loads the page again and reset quantity to 1($scope.quantity=1;). However, I want to assign the value of <%=product['qty'].to_i%>" to ng-model="quantity". Is it possible ?
var myapp = angular.module("mymodule", []);
myapp.controller('additctl', function ($scope) {
$scope.quantity = 1;
$scope.addval = function (val) {
console.log(val);
$scope.quantity = val + 1;
}
$scope.subval = function (val) {
if (val > 0) {
$scope.quantity = val - 1;
}
}
});
<form accept-charset="UTF-8" action="change_quantity" method="post">
<div ng-controller="additctl">
<button type="button" ng-click=subval(quantity)>-</button>
<input type="number" ng-model="quantity" value="<%=product['qty'].to_i%>" min="1" max="99" required>
<button type="button" ng-click=addval(quantity)>+</button>
<input type="submit" class="btn btn-success" name="button" value="update">
</div>
</form>