1

I'm trying to pass the value from an that is displayed through an ng-repeat into a function in my controller. The value displays properly in the HTML but when I get over to the function it displays the AngularJS expression instead of the actual value.

The HTML is as follows:

<li ng-repeat="account in accounts | filter:accountQuery" ng-click="setDisplayedFilters('{{account.AccountId}}')">
    <span>{{account.Name}}</span>
</li>

When I inspect the element inside of a browser (Chrome in this case) it displays the actual AccountId like it is supposed to.

The setDisplayedFilters function is as follows:

$scope.setDisplayedFilters = function(accountId){

    alert(accountId);
    $.each($scope.accounts, function(i, item){
        if(item.AccountId == accountId)
        {
            alert("Selected Account Id: " + accountId + "Matching Id in accounts Array: " + item.AccountId);
        }
    });
};

The first alert in the javascript will execute and displays "{{account.AccountId}}". The second one won't because it's comparing {{account.AccountId}} against the actual account Ids. So what I'm wondering is, what am I missing that is causing angular to interpret the AngularJS expresion literally rather than the value that should go in it's place?

Matt
  • 13
  • 4

1 Answers1

0

-> setDisplayedFilters(account.AccountId)

michael
  • 16,221
  • 7
  • 55
  • 60
  • I actually tried that and found that I receive an error (Error: [$parse:syntax]) when I try to remove the quotes from inside the setDisplayedFilters. – Matt Jan 07 '14 at 17:13
  • @Matt did you remove the quotes and the curly braces? – michael Jan 07 '14 at 17:18
  • I tried it right after reading your comment and when I inspected the element it read "acount.AccountId" and I thought it didn't work. I went back and actually tested it after this most recent comment and it worked! Could you possibly explain why it is that the syntax seems different in this case from any other way of getting values? – Matt Jan 07 '14 at 17:22
  • you will find your answer here: http://stackoverflow.com/questions/17878560/difference-between-double-and-single-curly-brace-in-angular-js – michael Jan 07 '14 at 17:27