efreeman
efreeman

Reputation: 473

ng-click within an ng-repeat, not formatting values correctly

New to AngularJS and my javascript skills aren't quite up to scratch.

I have an array of teams:

$scope.teams = ['Team-1', 'Team-2', 'Team-3']

and an ng-repeat, looping through these:

<span ng-repeat="team in teams">{{ $index + 1 }}: {{ team }}</span>

but I also want to add an ng-click to these elements, like this:

<span ng-repeat="team in teams" ng-click="addTeam(' {{ team | lowercase }}')">{{ team }}</span>

Clicking the element does add an entry to the array but it adds the value '{{ team | lowercase }}' rather than the intended lowercase team name. If I look at the code inspector, these values do display correctly in the elements.

i.e. ng-click="addTeam('team-1'), etc.

...is there something I'm missing from the ng-click?

Upvotes: 0

Views: 72

Answers (2)

Parthipan S
Parthipan S

Reputation: 180

This is the correct one.

<span ng-repeat="team in teams" ng-click="addTeam(team | lowercase)">{{ team }}</span>

Upvotes: 2

user3227295
user3227295

Reputation: 2156

this is the right syntax

<span ng-repeat="team in teams" ng-click="addTeam(team | lowercase)">{{ team }}</span>

Upvotes: 4

Related Questions