Ali Ali - 1 year ago 91
AngularJS Question

how to get button using id and call its click event - Angular

i have a button that call a function on ng-click , my issue is : how can i get this button using the id and call the click event on my Angular run function, this is my code :

<button ng-click="myfunction()" id="myButton">Click !!</button>['$rootScope',function($rootScope) {
// by default i want to click my button when the app is loaded

Note: i have a problem with "myfunction()" , this why i want to call it indirectly.

thanks in advance.

Answer Source

you can use ng-init

<button ng-click="myfunction()" id="myButton" ng-init="myfunction()">Click !!</button>

but if you still want:

How to trigger ng-click [AngularJS] programmatically

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download