I want to attach on click event to dynamically added li tag in angular I tried renderer also,
const classArr: any = document.querySelectorAll('.highlight');
classArr.forEach(element=>{
this.render.listen(element, 'click', (target)=>{
console.log('clicked', target);
})
});
but its not working on dynamic element.
Please help.
use event binding <ul> <li*ngFor="let i of slectedproduct"; let i = index> <span (click)="show(i)">{{slectedproduct.name}}</span> </li> </ul> binding and calling` `selectedevent; show(ind){ this.selectedevent = this.selectedproduct[ind]; }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.