How to manually trigger Button Click?


Hi there, second post today, next problem. I’d like to trigger a manually clickevent on an ionic.button, but as soon as you add the “ion-button” attribute, you get the error “Cannot read property ‘dispatchEvent’ of undefined”?!

sample code below:
Snippet from page.html
<button ion-button #mybutton (click)=“onClick()”>test //not working
<button #mybutton (click)=“onClick()”>test //working

snippet from page.ts
public onClick() {
let event = new MouseEvent(‘click’, { bubbles: true });
this.mybutton.nativeElement, ‘dispatchEvent’, [event]);
Any ideas?


And this is why I develop on typescript.

on .html
<button (click) = "onClick ()">Button</button>

on .ts

onClick () {
  //you can do whatever you want here!'


Are you serious? My example is in typescript! These are only snippets. My god…


Thought it was chinese. Did it work?


Hi Mica,

Did you find the solution for this? I have a problem to which this seems to be a solution.



Hey @SMhassan

Just use vanilla Javascript:



Thanks, was just wondering if there was an angular way to do it.


I have tried this, but with no success - the click event works fine using “ionic serve” but not in the emulator and ionic.view.
Any ideas ?


I encounter this problem too
cant do it in ios device
but I find out that if you add delay more than 2500ms like this

setTimeout(function () {
    }, 2500);

It will be ok

Anyone can help here?


Don’t use setTimeout() in app code. It will produce inconsistent results. Don’t access the DOM directly in app code. That’s Angular’s territory. Leave it alone.

The only situation in which you should even try to do something like “manually trigger button click” is in testing, and in that case, you can use this function (which I think I cribbed out of the Angular source):

export function click(el: DebugElement | HTMLElement, eventObj: any = ButtonClickEvents.left): void {
  if (el instanceof HTMLElement) {;
  } else {
    (<any>el).triggerEventHandler('click', eventObj);