0

I have an array that holds x number stocks in a JSON format and I am having a user enter the amount of shares they hold for each stock. My application will display the user's held value (valuePerShare * shares) for each stock.

<ul>
    <li ng-repeat="x in stocks">
        {{ x.symbol + ', ' + x.valuePerShare }}
        <p>Enter number of shares owned : <input type="text" ng-model="shares"></p>
        <p ng-if='shares'>{{shares}} shares. Value total: {{(x.valuePerShare*shares)}} </p>
    </li>
    <li> Summary: </li>
    <li> {{ stocks.length + ' stocks in portfolio' }} </li>
</ul>

How can I give a "portfolio total" in the summary that sums up x.valuePerShare*shares for all x stocks? Is there someway to grab that reactive value outside of the ng-repeat?

Steve C
  • 527
  • 1
  • 3
  • 14
  • I really think that should be a `total()` method on your controller, and not something you should do in your template. – Pevara Mar 04 '16 at 22:51
  • @Pevara how can i grab the user inputs from the controller? sorry if this is a dumb question. brand new to angular – Steve C Mar 04 '16 at 22:55
  • this should help: http://stackoverflow.com/questions/14410993/binding-ng-model-inside-ng-repeat-loop-in-angularjs – Pevara Mar 04 '16 at 23:00

0 Answers0