无法在 Angular 7(单击)函数中创建 window 警报

Unable to create window alert in Angular 7 (click) function

我无法在单击按钮时创建 Chrome 警报对话框。

<button mat-raised-button matStepperNext color="primary" [disabled]="formGroup.invalid" (click)="window.alert('Thanks for your submission!')>Submit</button>

我做错了什么?

您无法从 component.html 文件访问 "window"。

相反,请尝试在您的 component.ts 文件中创建一个警报功能,如下所示:

alert() {
  window.alert('test');
}

然后 运行 alert() 函数:

<button mat-raised-button matStepperNext color="primary" [disabled]="formGroup.invalid" (click)="alert()">Submit</button>

在你的 component.ts 文件中你可以说

window = window;

然后像在其他地方一样在 component.html 中使用 window

<button (click)="window.alert('Hello world')">
 This is a button
</button>