0

我是新來AngularJS,我嘗試做以下AngularJS納克 - 重複,納克 - 輸入文字奇怪的行爲模式

var app = angular.module('SomeApp', []); 

app.controller('QuotationController', function($scope) { 

    $scope.init = function(){ 
    $scope.chargableDescription = [""]; 
    $scope.chargablePrice = []; 
    $scope.chargableQuantity = []; 
    $scope.chargableTotal = []; 

    } 

    $scope.chargableInput = function($last){ 

    if ($last) { 
     $scope.chargableDescription.push([""]); 
    } 
    } 
}); 

基本的代碼,我想在這裏實現的是插入整個用戶在最後一個chargableDescription字段上輸入內容時的輸入組。

 <div class="chargable-group" ng-repeat="item in chargableDescription" > 

      <div class="col-md-3"> 
       <label class="form-control-label" for="l2" id="chargable-label">Chargable Item</label> 
      </div> 

      <div class="col-md-9" id="chargable-header"> 
       <textarea name="chargable[]" class="form-control dynamic chargable" placeholder="Chargable Description" ng-model="chargableDescription[$index]" ng-keypress="chargableInput($last)"> </textarea> 
       <br> 
       <input type="number" class="form-control" step="0.01" name="chargable-price-1" placeholder="Chargable Price" ng-model="chargablePrice[$index]"> 
       <br> 
       <input type="number" class="form-control" name="chargable-quantity-1" placeholder="Chargable Quantity" ng-model="chargableQuantity[$index]"> 
       <br> 
       <input type="number" class="form-control" step="0.01" name="chargable-total-1" placeholder="Chargable Total" readonly ng-model="chargableTotal[$index]" > 
      </div> 

     </div> 

它的伎倆,但是,我不知道爲什麼,當我做textarea的任何輸入,將光標一次,我輸入一個字符了。 如何消除此行爲以及導致此行爲的因素是什麼?

UPDATE:

解決 我加了NG-模型選項= {updateOn: '模糊'}和它看起來像它解決了問題

+0

請刪除該問題,因爲它總是會顯示爲未答覆,否則當他們開始閱讀時會浪費任何人的時間以解決問題。否則,在標題本身寫[Solved]。 –

回答

0

它爲我https://plnkr.co/IV9t4fhln5v3l81NHaPC

你叫什麼角度版本?

(function() { 

    'use strict'; 

    var app = angular.module('SomeApp', []); 

    app.controller('QuotationController', function($scope) { 

    $scope.init = function() { 
     $scope.chargableDescription = [""]; 
     $scope.chargablePrice = []; 
     $scope.chargableQuantity = []; 
     $scope.chargableTotal = []; 

    } 

    $scope.chargableInput = function($last) { 

     if ($last) { 
     $scope.chargableDescription.push([""]); 
     } 
    } 

    $scope.init(); 
    }); 


})(); 
+0

我可以看到它正在處理上面的鏈接,但它不適用於我。 但是爲什麼你添加$ scope.init();之後的邏輯?這不是刷新初始值嗎?我添加了ng-model-options = {updateOn:'blur'},它工作得很好,但我很好奇爲什麼。 你知道爲什麼嗎? 謝謝你的回答,並希望你能向我解釋,因爲我對AngularJS真的很陌生。 @Karl San Gabriel –