2016-11-22 55 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

相关问题