I am new to angular, and trying to build an app in ionic. I have 2 fields on screen, and I want to implement the following.
- when user enters something in the
price
field, I want to updateweight
field accordingly. - when user enters something in the
weight
field, I want to update theprice
field.
Here is my code.
<div class="col col-50">
<div class="card">
<label class="item item-input">
<input ng-model="sale_item_weight" value="{{ sale_item_weight }}" ng-change="syncWithItemPrice()" type="number" placeholder="Enter Weight">
</label>
</div>
</div>
<div class="col col-50">
<div class="card">
<label class="item item-input">
<input ng-model="sale_item_price" value="{{ sale_item_price }}" ng-change="syncWithItemWeight()" type="number" placeholder="Enter Price">
</label>
</div>
</div>
and in my controller I have these methods:
$scope.syncWithItemWeight = function() {
var itemPrice = $scope.sale_item_price;
$scope.sale_item_weight = parseInt(itemPrice) * 2;
}
$scope.syncWithItemPrice = function() {
var itemWeight = $scope.sale_item_weight;
$scope.sale_item_price = parseInt(itemWeight) / 2;
}
when I change one field the other one doesn't get updated. The functions are getting called, I have made sure of that by adding an alert
to them.
Any help will be much appreciated.