0

enter image description here

This is the code, it's using the DOM Selector in the Ionic & Angular Framework. I'm unsure why the console.log of "placing order" does not display when the button is clicked. I tried to use many alternatives like ngClick, ng-click, ngclick or changing the syntax of the function to this.placeOrder(), placeOrder = () => {}, etc but all did not work.

Thank you in advance!

Tomislav Stankovic
  • 3,080
  • 17
  • 35
  • 42
  • Are you using angular 2+ or angular js version? Please post a reproducable code snippet. – Nitheesh Jul 30 '20 at 02:47
  • @Nitheesh here is a snippet of the code. var x = document.getElementById("elementToReplace"); x.innerHTML = 'Place Order' placeOrder() { console.log("placing order"); } – user14019419 Jul 30 '20 at 03:16
  • https://stackoverflow.com/questions/37676726/angular-2-innerhtml-click-binding – Nitheesh Jul 30 '20 at 03:24
  • Does this answer your question? [Angular 2 innerHTML (click) binding](https://stackoverflow.com/questions/37676726/angular-2-innerhtml-click-binding) – Nitheesh Jul 30 '20 at 03:24
  • @Nitheesh not really because its actually replacing the whole ion-content element. And i understand it's frowned upon but i wasn't using the Ref method instead just the js DOM selector method. All the other functions are working but just not the clicking of the button. – user14019419 Jul 30 '20 at 04:10

1 Answers1

0

Just add a listener of clicking event to the ion-button:

x.querySelector('ion-button').addEventListener('click', () => this.placeOrder());

Working example:

https://stackblitz.com/edit/inner-html-event

critrange
  • 5,652
  • 2
  • 16
  • 47