如何从多个ng-repeat指令内部传递params?

时间:2017-09-25 13:03:11

标签: angularjs

我在通过ng-repeat传递参数时遇到问题。我有三个嵌套的ng-repeat,我希望将一些数据传递给我的函数。

这是我的HTML:

<div ng-repeat="x in players" ng-controller="filterClubCtrl">
    <div ng-repeat="z in playerLastDays" ng-if="x.player_id == z.player_id">
        <div ng-repeat="y in teams" ng-if="y.id == z.team_id">
            <div class="percentageWeeks" ng-if="filterSmalerThan(z.avgDays,x.avgWeek)">
                <img class="img-responsive" src="partials/club/img/arrow_down.png" />
                <p>{{weeklyGrowth(z.avgDays, x.avgWeek, y.avgWeekTeam) | number:2 }}% in last {{days}} days</p>
            </div>
        </div>
    </div>
</div>

这是我的控制器的功能:

$scope.weeklyGrowth = function(avgDays, avgWeek, avgWeekTeam) {
    $scope.avgWeeklyGrowth = 0;
    $scope.avgWeeklyGrowt = avgDays / avgWeekTeam * 100 - avgWeek / avgWeekTeam * 100;
    return $scope.avgWeeklyGrowth;
};

感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

我认为这是由你方法中的拼写错误引起的;因为您错误地输入值$scope.avgWeeklyGrowth,导致声明新值$scope.avgWeeklyGrowt,并将$scope.avgWeeklyGrowth的值保持为零:

$scope.weeklyGrowth = function (avgDays, avgWeek, avgWeekTeam) {

$scope.avgWeeklyGrowth = 0; 

// Old line that makes the issue: $scope.avgWeeklyGrowt = avgDays / avgWeekTeam * 100 - avgWeek / avgWeekTeam * 100;

$scope.avgWeeklyGrowth = avgDays / avgWeekTeam * 100 - avgWeek / avgWeekTeam * 100;

return $scope.avgWeeklyGrowth;}

答案 1 :(得分:0)

这是JSON中的错误。我把y.avgWeekTeam但是在JSON中是avgWeekteam。

谢谢你的帮助!