How can i trigger a click event for li elements specifying their index from the angularjs directive? I have tried using $first for triggering click for the first element, but its not working.
Thanks for any help.
How can i trigger a click event for li elements specifying their index from the angularjs directive? I have tried using $first for triggering click for the first element, but its not working. Thanks for any help. |
|||||||||||||
|
Here is perhaps a different way for you to achieve this. Pass into the directive both the index and the item and let the directive setup the html in a template: Demo: http://plnkr.co/edit/ybcNosdPA76J1IqXjcGG?p=preview html:
js directive:
You probably would be better off adding a ng-click to the image as pointed out in another answer. Update The link for the demo was incorrect. It has been updated to: http://plnkr.co/edit/ybcNosdPA76J1IqXjcGG?p=preview |
|||||||||||||||||||||
|
This is more the Angular way to do it: http://plnkr.co/edit/xYNX47EsYvl4aRuGZmvo?p=preview
|
|||
|
This is an extension to Langdon's answer with a directive approach to the problem. If you're going to have multiple galleries on the page this may be one way to go about it without much fuss. Usage:
|
|||
|
This is how I was able to trigger a button click when the page loads.
A simple directive that takes the index from the ng-repeat and uses a condition to call the first button in the index and click it when the page loads.
This was the only way I was able to even trigger an auto click programmatically in the first place. |
|||
|