Ali Ali - 5 months ago 7
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>


app.run(['$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

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

Comments