Angular 6如何在单击按钮后显示消息

时间:2018-09-25 19:03:03

标签: javascript angular typescript angular6

我正在一个项目中,该项目包含一个用于保存更改的按钮。我只想单击按钮后3秒后显示示例消息。像下面的例子一样

<div>
<button *ngIf="show" class="fade in" role="">Save</button>
   <p SOW THIS MESSAGE 3s AFTER CLICK SAVE> <strong>just Saved!</strong> Your changes has been saved.<p>

1 个答案:

答案 0 :(得分:0)

.html:

<button (click)="showMessageSoon()">Show Message</button>
<p *ngIf="showMyMessage">hello there</p>

.ts:

public showMyMessage = false

showMessageSoon() {
  setTimeout(() => {
    this.showMyMessage = true
  }, 3000)
}