AngularJS calculate a dynamic number of variables in braces -


I want to calculate the total amount of dynamic number of variables within the brace syntax of an angle.

I would look for the commonly used loop:

  var total = 0; (Total = = Objects [x] .num;}  

I will call it {{total} for (x = 0; x & lt; objects; long; x ++) }} or {{total ()}} and update anytime, whenever the one of the variables is changed.

Here's what you want:

HTML < / P>

  
ng-app = "myApp" ng-controller = "ctrl" ng-strict-di> {{total ()}}

& Lt; input type = "text" ng-model = "item.num" ng-repeat = "items in items" />

JS:

  Angular. Module ('myApp', & gt; [] Controller ('ctrl', function $ Scope) {angular.extend ($ scope, {objects: [{num: 7}, {num} 8}, {num: 9}], total: function () { Var res = 0; for (var i = 0; i & lt; $ scope.objects.length; i ++) res + = parseInt ($ scope.objects [i] .num); return ridge;}}); });   Update  to update  is to test that the new update update of the object is being updated with code as follows:  
  setInterval (function) {$ Scope.objects [1] .num ++; $ Scope $ Apply ();}, 500); // Increase the number of the second object from 1, every half of the second  

to test that it is still updating while adding new items, in this way the code Play with:

set interval (function () {$ scope.objects.push ({num: Math.floor (Math.rendum (* * 100}});}, 5000); // Add new object, with random number: value, every 5 seconds

Comments

Popular posts from this blog

winforms - C# Form - Property Change -

javascript - amcharts makechart not working -

java - Algorithm negotiation fail SSH in Jenkins -