我正在尝试为全局变量$rootScope.pageClass
分配ng重复循环中单击的项的值,但不确定这是否正确。
控制器
.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}}
您不需要使用{{}}向函数传递参数。试试这个ng-click="setTeamClass(team.teamName)"