JavaScript AngularJS - add all values in table row dynamically angularjs get table values

I'm having a table where the user will enter data in the fields when they enter each value in each cell, the last cell needs to be updated with its total. with this snippet I'm getting 45+90+36. I know its easy with jQuery, but I wanted to do this as simple as possible in Angular.

<tr>
  <td rowspan="4"><span class="textRotate">TESTING</span>
  </td>
  <td>XXXX</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxPrevention">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxAppraisal">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxInternalFailure">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxxExternalFailure">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxPerformance">NA</td>
  <td ng-model="tableVal.xxxTotal">{{tableVal.xxxxPrevention + tableVal.xxxxAppraisal}}</td>
  <td>%</td>
</tr>
Answer:1

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.4.11/d3.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="">
<tr>
  <td rowspan="4"><span class="textRotate">TESTING</span>
  </td>
  <td>XXXX</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxPrevention">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxAppraisal">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxInternalFailure">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxxExternalFailure">$</td>
  <td>
    <input id="testingInput" type="text" ng-model="tableVal.xxxxPerformance">NA</td>
  <td ng-model="tableVal.xxxTotal">{{ (tableVal.xxxxPrevention|number) -- (tableVal.xxxxAppraisal|number)}}</td>
  <td>%</td>
</tr>
  </div>
Answer:2

You have two options:

Solution 1:

You can make your type of input as number instead of text (for HTML 5):

<tr>
  <td rowspan="4"><span class="textRotate">TESTING</span>
  </td>
  <td>XXXX</td>
  <td>
    <input id="testingInput" type="number" ng-model="tableVal.xxxxPrevention">$</td>
  <td>
    <input id="testingInput" type="number" ng-model="tableVal.xxxxAppraisal">$</td>
  <td>
    <input id="testingInput" type="number" ng-model="tableVal.xxxxInternalFailure">$</td>
  <td>
    <input id="testingInput" type="number" ng-model="tableVal.xxxxxExternalFailure">$</td>
  <td>
    <input id="testingInput" type="number" ng-model="tableVal.xxxxPerformance">NA</td>
  <td>{{tableVal.xxxxPrevention + tableVal.xxxxAppraisal}}</td>
  <td>%</td>
</tr>

Solution 2:

Use the parseInt() method before sum:

<td>{{parseInt(tableVal.xxxxPrevention) + parseInt(tableVal.xxxxAppraisal)}}</td>
Answer:3

Why not using $scope.$watch().

Ex.

$scope.$watch('tableVal', function (nV, oV) {
    // nV == new value, oV == old value
    if (nV != oV) {
        // Run some function here to update total and assign it to $scope.property
    }
}, true)
Answer:4

I'd like to reduce my array of objects using lodash. My object: [ {date: '01/01/2016', price: 5}, {date: '01/01/2016', price: 10}, {date: '01/02/2016', price: 500} ] After the reduce: [...

I'd like to reduce my array of objects using lodash. My object: [ {date: '01/01/2016', price: 5}, {date: '01/01/2016', price: 10}, {date: '01/02/2016', price: 500} ] After the reduce: [...

  1. reduce array with one element
  2. reduce array with objects
  3. array_reduce with keys
  4. reduce with array
  5. array reduce with index
  6. array reduce with initial value
  7. reduce with array javascript
  8. array reduce with promise
  9. array reduce with condition
  10. array reduce with strings
  11. array reduce with keys php
  12. reduce with array ruby
  13. array reduce with examples
  14. reduce array of objects javascript
  15. reduce array of objects js
  16. reduce array of objects into one object
  17. reduce array to unique values
  18. reduce array to string javascript
  19. reduce array by adding elements
  20. reduce array of booleans

I'm new to web crawling. I am trying to crawl a webpage using java and I encounter a problem. I need to get the link in a 'HTML Tag' whose href is a javascript function. I have no idea how to get the ...

I'm new to web crawling. I am trying to crawl a webpage using java and I encounter a problem. I need to get the link in a 'HTML Tag' whose href is a javascript function. I have no idea how to get the ...

Hi I have created a dom using raw javascript DOM: Javascript code: var parentElm = document.createElement("div"); var child1 = document.createElement("p"); var child2 = document.createElement("p"); ...

Hi I have created a dom using raw javascript DOM: Javascript code: var parentElm = document.createElement("div"); var child1 = document.createElement("p"); var child2 = document.createElement("p"); ...

I am creating dynatree. I want to set first node of dynatree to be selected on opening dynatree. I set select= tree in json for first element. but it does't work. I want to skip adding select property ...

I am creating dynatree. I want to set first node of dynatree to be selected on opening dynatree. I set select= tree in json for first element. but it does't work. I want to skip adding select property ...

  1. dynatree select first node