将变量传递给ng-repeat过滤器

时间:2016-04-10 21:49:14

标签: angularjs

我是Angular的新手,我试图将变量传递给过滤器,但我没有运气。当我对值进行硬编码但它似乎没有接受该值时,它可以正常工作。

JS

var app = angular.module('footballApp', []);

app.controller("TeamCtrl", function($scope, $http){

    $http.get("clubs.php/teams").success(function (data){
        $scope.teams = data.team;
    }).error(function (){
        alert("an error has occured");
    });

  $http.get("players.php/players").success(function (data){
        $scope.players = data.player;
        console.log($scope.players);
    }).error(function (){
        alert("an error has occured");
    }); 

});

HTML

<script type="text/ng-template" id="team-single.html">
    <div class="team-box">
        <div class="badge">
            <img src="logo.png" width="100" height="100"></div>
        <div class="team-name">{{x.club_name}}</div>
        <p><b>Club Manager:</b> {{x.club_manager}}</p>
        <p><b>Ground:</b> {{x.club_ground}}</p>
        <p><b>Nickname:</b> {{x.club_nickname}}</p>
        <div class="team-p">{{x.club_info}}</div>
        <div class="key-players">
            Key Players
        </div>

        <div class="players">
            <ul class="player-list">
                <li ng-repeat="player in players | filter: { club_name: '{{player.club_name}}' }" data-toggle="modal" data-target="#{{player.id}}">{{player.player_name}}</li>
            </ul>
        </div>
    </div>
</script>


<div class="row teams" ng-controller="TeamCtrl">
    <div class="container">
        <div class="col-md-4" ng-repeat="x in teams" ng-include="'team-single.html'"></div>
    </div>

</div>

除了我使用ng-repeat和过滤器来过滤club_name显示的列表之外,一切正常。谁能告诉我哪里出错?

0 个答案:

没有答案