将全局变量设置为单击项目angularjs的值

时间:2015-02-11 18:55:41

标签: angularjs

我正在尝试使用在ng-repeat循环中单击的项目的值来分配全局变量$rootScope.pageClass,但不确定这是否正确。

控制器

.controller('teamController', function($scope, $routeParams, $rootScope, footballdataAPIservice) {
    $scope.id = $routeParams.id;
    $scope.team = [];

    $scope.setTeamClass = function(teamname) {  
$rootScope.pageClass = teamname;
}


<tr ng-repeat="team in teamsList.standing">
        <td>
            <a ng-click="setTeamClass( {{teamName(team.teamName)}} )" href="#/teams/{{teamID(team._links.team.href)}}">
              {{teamName(team.teamName)}}
            </a>

它给了我这个错误:

invalid key at column 16 of the expression [setTeamClass( {{team.teamName}} )] starting at [{team.teamName}} 

1 个答案:

答案 0 :(得分:1)

您无需使用{{}}将参数传递给函数。试试这个 ng-click =“setTeamClass(team.teamName)”

相关问题