Add the value between two Angular input

2
<label>Capital
  <input type="number" ng-model="vm.capital" ng-keyup="vm.total()">
</label>

<label>Honorarios
  <input type="number" ng-model="vm.honorarium" ng-keyup="vm.total()">
</label>


<h1>{{ vm.sum }}</h1>

The function:

this.total = function(){
    this.sum = capital + honorarium;
}

I need to make the sum between capital and honorarium. But my solution does not work, maybe I have some problem in logic.

    
asked by Matias Cazas 09.02.2018 в 15:48
source

1 answer

1

If it's the only thing you need, you can use it in the following way

   <label>
        Capital
        <input type="number" ng-model="capital">
    </label>

    <label>
        Honorarios
        <input type="number" ng-model="honorarium">
    </label>


    <h1>{{capital + honorarium }}</h1>

You do not need to use any ng-X function to do this process, remember that these variables are kept in the $ scope, who is in charge of updating the information of them immediately ..

what you do inside the h1 is only add what is contained in your ng-model ..

    
answered by 09.02.2018 / 17:51
source