【发布时间】:2021-05-28 19:01:22
【问题描述】:
我有 3 个部分/div,我想一个接一个地显示。例如,一旦我单击“显示进度”按钮,首先“第一个”div 应该只显示,几秒钟后“第二个”div 应该显示隐藏“第一个”一个,然后在几秒钟后“第一个”和“第二个”div 应该隐藏第三个应该显示。它第一次工作正常,但是当我再次单击时它不起作用。有没有更好的方法我可以做到。这是代码https://stackblitz.com/edit/angular-atf7ja?file=src%2Fapp%2Fapp.component.html
app.component.html
<hello name="{{ name }}"></hello>
<p>
Start editing to see some magic happen :)
</p>
<button (click)="showdivs()">show progress</button>
<div *ngIf="first">First div</div>
<div *ngIf="second">Second div</div>
<div *ngIf="third">Third div</div>
app.component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
first: boolean = false;
second: boolean = false;
third: boolean = false;
name = 'Angular';
ngOnInit() {}
showdivs() {
this.first = true;
setTimeout(() => {
this.first = false;
this.second = true;
}, 4000);
setTimeout(() => {
this.first = false;
this.second = false;
this.third = true;
}, 8000);
}
}
【问题讨论】:
标签: javascript html angular