我正在尝试使用在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}}
答案 0 :(得分:1)
您无需使用{{}}将参数传递给函数。试试这个 ng-click =“setTeamClass(team.teamName)”