Reputation: 107
contend included in app.component.html file
<button onclick="myfunction()">Click me </button>
<script src="one.js"></script>
one.js file
function myfunction() {
alert();
}
Upvotes: 1
Views: 5133
Reputation: 173
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.
Upvotes: 3
Reputation: 16384
In Angular the regular onclick
should be (click)
or on-click
, like this:
<button (click)="myfunction()">Click me </button>
Or this:
<button on-click="myfunction()">Click me </button>
For more info you can read about the event binding in Angular.
Upvotes: 1