我是Angular的新手,尝试构建离子应用程序。我在屏幕上有两个字段,我想要实现以下内容。角度离子数据绑定问题
- 当用户在
price
字段中输入一些东西,我要作相应的更新weight
场。 - 当用户在
weight
字段中输入内容时,我想更新price
字段。
这是我的代码。
<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>
,并在我的控制器我有以下方法:
$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;
}
当我改变一个领域的另一个没有更新。功能正在调用,我已经通过添加alert
来确保它们。
它似乎是为我工作正常,你可以发表你的整个代码。它最可能是一个错字。看到这[链接](https://plnkr.co/edit/1WUamNKfg8IfRufwNs5r?p=info) –