输入更改后更新文本

时间:2016-04-20 02:55:04

标签: angularjs

System Link

JSFiddle

选择项目(来自数据库并返回项目的价格并在成本列上更新)后,我希望Total列根据之前返回的价格进行更新。

然而,经过几次试用事件(ng-click,focus等)后,Total列仍然无法更新。

HTML:

      <div class="row invoice-item" data-ng-repeat="item in invoice.items" ng-animate="'slide-down'">
    <div class="col-xs-1 remove-item-container">
      <a href ng-hide="printMode" ng-click="removeItem(item)" class="btn btn-danger">[X]</a>
    </div>
    <div class="col-xs-5 input-container">
      <input ng-model="item.description" placeholder="Item Name" size="35" list="myBuku" id="item_{{$index}}" ng-keyup="suggest(item.description)" ng-blur="check(item.description, $event)"/>
      <datalist id="myBuku">
      </datalist>
    </div>
    <div class="col-xs-2 input-container">
      <input ng-model="item.qty" value="1" size="4" ng-required ng-validate="integer" placeholder="Quantity"/>
    </div>
    <div class="col-xs-2 input-container">
      <input ng-model="item.cost" id="money_{{$index}}" value="0.00" ng-focus="focusMoney(item.description, $event)" ng-required ng-validate="number" size="6" placeholder=""/>
    </div>
    <div class="col-xs-2 text-right input-container">
      {{item.cost * item.qty | currency: currencySymbol}}
      <input type="text" ng-model="total" bound-model="item.qty * item.cost"/>
    </div>
  </div>

函数用于更新成本列上的输入。

    $scope.focusMoney = function(barang, obj){
  var elm = angular.element(obj.currentTarget);
  var elmId = elm.attr('id');
  $http({
    method: "POST",
    url : './hargaBarang.php',
    data: {barang: barang},
    headers: {'Content-Type' : 'application/x-www-form-urlencoded; charset=utf-8'}
  }).success(function(response){
    var myEl = angular.element( document.querySelector("#"+elmId) ).val(response);
    console.log(myEl);
  });
};

谢谢。

0 个答案:

没有答案