How to perform javascript onclick operation in Angular 5?

Issue

contend included in app.component.html file

<button onclick="myfunction()">Click me </button>
<script src="one.js"></script>

one.js file

function myfunction() {
  alert();
}

Solution

In app.component.html add click event:

<button (click)="myfunction()">Click me </button>

In app.component.ts add its corresponding function:

export class AppComponent {
  title = 'app';
 myfunction(){
      alert();
  }
}

Its working for me.

Answered By – Sajith

Answer Checked By – Robin (AngularFixing Admin)

Leave a Reply

Your email address will not be published.