基于ng重复中的值的角度增加范围值

Angular increase scope value based on values in ng-repeat

本文关键字:增加 范围 ng 基于      更新时间:2023-09-26

我想通过在ng重复中使用值来增加$scope中的值的数量。我想知道这是否可能。

我有以下

<div ng-repeat="field in selected.inhoud.fields">
  <p>Veldnaam: {{field.title}}</p>
  <p>Grootte in %:
    <input type="range" min="10" max="80" ng-model="field.width" ngvalue="field.width" />
  </p>
</div>

我想得到所有场的总宽度。宽度。

感谢

您可以创建一个传递参数的函数(在本例中为$index),并执行所需的任何计算。

<div ng-repeat="field in selected.inhoud.fields">
        <p>Veldnaam: {{field.title}}</p>
        <p>Grootte in %: {{ calculateValue($index) }}
           <input type="range" min="10" max="80" ng-model="field.width" ngvalue="field.width"/>
        </p>
    </div>
var app = angular.module('angularjs-app', []);
app.controller('MainCtrl', function($scope) {
  $scope.data.calculateValue = function(index){
     console.log('some value:'+index*.1);
     $scope.increment += index; 
  }; 
  console.log($scope.increment);
});