2016-11-22 37 views
0

我是angularjs的新手,並且已經在問題中陷入困境.... 想要動態顯示第三列中第二列的兩列的一些計算。 ..ie假設用戶在兩列和三列中鍵入10和20時應該動態填充爲200(例如)。在angularjs中動態顯示第三列表中的兩列的總和

請建議我如何在angularjs中實現這一點。

我正在使用ng-repeat來填充HTML中的簡單表格。 HTML代碼

<table class="table table-hover"> 
                <thead> 
                 <tr> 
                  <th class="col-sm-1" style="text-align:center">S.No.</th> 
                  <th class="col-sm-5" style="text-align:center">Certificate Name</th> 
                  <th class="col-sm-1" style="text-align:center">No of New Certificate</th> 
                  <th class="col-sm-1" style="text-align:center">No of Duplicate Certificate</th> 
                  <th class="col-sm-1" style="text-align:center">Transcript Amount</th> 
                 </tr> 
                </thead> 
                <tbody> 
                 <tr ng-repeat="payment in TRAN_PaymentDetail"> 
                  <td class="col-sm-1" style="text-align:center">{{$index+1}} 
                  </td> 
                  <td class="col-sm-5"> 
                   <input type="text" disabled class="form-control" ng-model="payment.Title" required /> 
                  </td> 
                  <td class="col-sm-1"> 
                   <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.NoofNewCertificate" /> 
                  </td> 
                  <td class="col-sm-1"> 
                   <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.NoofDuplicateCertificate" /> 
                  </td> 
                  <td class="col-sm-1"> 
                   <input type="text" readonly name="NewTranscript" class="form-control" ng-model="payment.HeadAmount" value="{{CalulateHeadAmount()}}" /> 
                  </td>                
                 </tr> 
                </tbody> 
               </table> 

我想告訴NoofNewCertificate和NoofDuplicateCertificate的基礎上HeadAmount。只要用戶輸入這些值,HeadAcount就應該動態填充。

由於提前 問候,

+0

你可以看看我的答案..希望對你有用。讓我知道這是否解決您的問題或需要別的東西。 –

回答

0
var myApp = angular.module("myApp", []); 

myApp.controller('myCtrl', function ($scope) { 

    $scope.Data = [{ "Col1": 1, "Col2": 1 }]; 


}); 


<div ng-app="myApp" ng-controller="myCtrl"> 

    <table class="table table-hover"> 
     <thead> 
      <tr> 
       <th class="col-sm-1" style="text-align:center">S.No.</th> 

       <th class="col-sm-1" style="text-align:center">Col 1</th> 
       <th class="col-sm-1" style="text-align:center">Col 2</th> 
       <th class="col-sm-1" style="text-align:center">Sum</th> 
      </tr> 
     </thead> 
     <tbody> 
      <tr ng-repeat="payment in Data"> 
       <td class="col-sm-1" style="text-align:center"> 
        {{$index+1}} 
       </td> 
       <td class="col-sm-1"> 
        <input type="number" min="0" class="form-control" ng-model="payment.Col1" required /> 
       </td> 
       <td class="col-sm-1"> 
        <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.Col2" /> 
       </td> 
       <td class="col-sm-1"> 
        <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.Col1 + payment.Col2" /> 
       </td> 

      </tr> 
     </tbody> 
    </table> 
</div> 
+0

而不是促進你的Youtube頻道,你可以給出一個答案,只是說。如果我正確理解他的問題,那麼根本不需要過濾器。 – trichetriche

+0

我沒有宣傳我的視頻頻道,我只是在幫助他。雖然我已刪除。 –

+0

男人,我們可以看到你編輯的東西。沒關係,你不會被禁止的,我也不會報告你,但我只是說你必須避免這種「幫助」。 – trichetriche

0
<tbody> 
    <tr ng-repeat="payment in TRAN_PaymentDetail"> 
     <td class="col-sm-1" style="text-align:center">{{$index+1}}</td> 
     <td class="col-sm-5"> 
      <input type="text" disabled class="form-control" ng-model="payment.Title" required /> 
     </td> 
     <td class="col-sm-1"> 
      <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.NoofNewCertificate" /> 
     </td> 
     <td class="col-sm-1"> 
      <input type="number" min="0" name="NewTranscript" class="form-control" ng-model="payment.NoofDuplicateCertificate" /> 
     </td> 
     <td class="col-sm-1"> 
      <input type="text" readonly name="NewTranscript" class="form-control" ng-model="payment.HeadAmount" ng-value="payment.NoofNewCertificate * 1 + payment.NoofDuplicateCertificate * 1" /> 
     </td>                
    </tr> 
</tbody> 

假設你的2個輸入是由用戶輸入的值,最後一個是增加了兩個。

+0

單元格中的計算值感謝trichetriche您的建議... 我試過ng值,以及它的工作也。 ,但在單元格上使用ng-change來計算所需的值,並使用ng-model綁定要顯示在視圖中的值。 再一次感謝.. – user4365176

+0

沒問題,記得標記一個有效的答案作爲驗證,以幫助那些與你有同樣問題的人。 – trichetriche

相關問題