Faiq Faiq - 3 months ago 31
HTML Question

How to pass angular 2 variable's value to javascript function?

enter image description here

This is my image
I want to pass "c.name" and "c.image_Url" in onclick function as given in image

Answer
<div *ngFor="let c of categories" (click)="selectedCategory(c.name,c.image_url)">

     //<---note (click) event - angular2 way element's click binding
     ....

</div>

In component,

selectedCategory(value1,value2){
 console.log(value1);
 console.log(value2);
}