簡體   English   中英

基於ng-repeat中的值的角度增加范圍值

[英]Angular increase scope value based on values in ng-repeat

我想通過使用ng-repeat中的值來增加$ 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>

我想獲取所有field.width的總寬度。

謝謝

您可以創建一個傳遞參數的函數(在此example $ 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);
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM