最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I want to execute ng-click function via console,is it possible? - Stack Overflow

programmeradmin3浏览0评论

I want to call ng-click function using console. Is it possible?

<button class="btn btn-sm btn-block btn-green ng-binding" id="login-button"ng-click="onLoginClick($event)">Log In</button>

I want to call ng-click function using console. Is it possible?

<button class="btn btn-sm btn-block btn-green ng-binding" id="login-button"ng-click="onLoginClick($event)">Log In</button>
Share Improve this question edited May 1, 2018 at 8:55 Vega 28.7k28 gold badges120 silver badges145 bronze badges asked May 1, 2018 at 5:44 user9380190user9380190 771 silver badge5 bronze badges 1
  • If not, then there are other ways to test onLoginClick, right? – Tim Biegeleisen Commented May 1, 2018 at 5:47
Add a ment  | 

4 Answers 4

Reset to default 5

You can try this:

angular.element('#login-button').triggerHandler('click');

this will work for sure.

You can use javascript getelementbyid as following:

document.getElementById("login-button").click();

The only way it es to my mind to do it is using jQuery to select the element (button) and then trigger the click:

$( "#login-button" ).trigger( "click" );

Try it and let us know if it works, here you are a JSFiddle: link

Yes. You can invoke/execute a function using window.function_name() or function_name()

发布评论

评论列表(0)

  1. 暂无评论