Jose Mendez Jose Mendez - 1 month ago 5
AngularJS Question

angular {{ }} expression not resolving inside ng-click

The line below fails, the console shows "index is undefined" when the image is clicked:

<img class="full-image" ng-click="addFavorite({{}})" ng-src="{{baseURL+dish.image}}" title="{{}}" >

However, any of the other expressions resolve the interpolation just fine. I even added this one to prove I could show the dish id:

<h2>{{}} {{}}

And I get the dish name and to the right the dish id printed out on the browser.

If I swap the expression to a hardcoded value such as 2, the function addFavorite() runs fine on click:

<img class="full-image" ng-click="addFavorite(2)" ng-src="{{baseURL+dish.image}}" title="{{}}" >

What could be the error that prevents the addFavorite() funcion from resolving the {{}} expression?


when you're using like ng-click you don't need to use {{}}

Update :

It is helpful to you