admin管理员组

文章数量:1023009

I'm working in a project that includes a button to save a change. I just wanted a sample message shown after 3s after the button is clicked. smt like the below example

<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>

I'm working in a project that includes a button to save a change. I just wanted a sample message shown after 3s after the button is clicked. smt like the below example

<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>

Share Improve this question edited Sep 25, 2018 at 20:52 danday74 57.5k55 gold badges269 silver badges333 bronze badges asked Sep 25, 2018 at 19:03 Hicham MARKUSHicham MARKUS 491 gold badge3 silver badges7 bronze badges 1
  • When you click the save button, create a timer, and pass a call back to set the show variable after 3 seconds – johnny 5 Commented Sep 25, 2018 at 20:36
Add a ment  | 

1 Answer 1

Reset to default 2

.html:

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

.ts:

public showMyMessage = false

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

I'm working in a project that includes a button to save a change. I just wanted a sample message shown after 3s after the button is clicked. smt like the below example

<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>

I'm working in a project that includes a button to save a change. I just wanted a sample message shown after 3s after the button is clicked. smt like the below example

<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>

Share Improve this question edited Sep 25, 2018 at 20:52 danday74 57.5k55 gold badges269 silver badges333 bronze badges asked Sep 25, 2018 at 19:03 Hicham MARKUSHicham MARKUS 491 gold badge3 silver badges7 bronze badges 1
  • When you click the save button, create a timer, and pass a call back to set the show variable after 3 seconds – johnny 5 Commented Sep 25, 2018 at 20:36
Add a ment  | 

1 Answer 1

Reset to default 2

.html:

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

.ts:

public showMyMessage = false

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

本文标签: javascriptAngular 6 How to show Message after button is clickedStack Overflow