如何在Angular 5中执行javascript onclick操作?

How to perform javascript onclick operation in Angular 5?

竞争包含在 app.component.html 文件中

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

one.js 文件

function myfunction() {
  alert();
}

在Angular中,常规onclick应该是(click)on-click,像这样:

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

或者这样:

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

有关详细信息,您可以阅读 Angular 中的 event binding

在app.component.html添加点击事件:

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

在app.component.ts中添加其对应的函数:

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

它对我有用。