Avraam Mavridis
Avraam Mavridis

Reputation: 8920

How to pass an Angular's value to a function

I want to call a function fadeOut() passing to it an index number generated by ng-repeat. I tried this

   <img ng-src={{element.image}} class="portofolio-image" 
id="portofolio-image{{$index}}"
 ng-click="fadeOut({{$index}})">

but there is a parsing error, and this

    <img ng-src={{element.image}} class="portofolio-image"
 id="portofolio-image{{$index}}"
 ng-click="fadeOut('{{$index}}')">

which passes the "{{$index}}" string. Any idea how can I solve this?

Upvotes: 3

Views: 112

Answers (1)

Kareem Elshahawy
Kareem Elshahawy

Reputation: 1421

You can use fadeOut($index) as follows:

    <img ng-src={{element.image}} 
     class="portofolio-image" 
     id="portofolio-image{{$index}}" 
     ng-click="fadeOut($index)">

Upvotes: 8

Related Questions