Phenomenon description: Just after entering the page, there will be a 2-3 second blank in the carousel section, and then it will be displayed normally afterwards;
Framework: Angular + NG-ZORRO-antd
Solution: It is because the time interval of automatic switching leads to blank space. I set an identifier. When it is false at the beginning, it displays a newly added carousel component with no automatic switching and a time interval of 0; it changes immediately after the page is loaded. If true, display my original component again;
code:
/**
* html 重点在于ngIf条件,如果init则显示时间间隔为5s的自动切换轮播图,
* 否则显示不自动切换时间间隔为 0的轮播图
*/
<nz-content class="left-images">
<nz-carousel *ngIf="init" #carousel [nzEffect]="effect" [nzAutoPlay]="true"
[nzDots]="false" [nzAutoPlaySpeed]="5000">
<div class="go" nz-carousel-content *ngFor="let index of array">
<div *ngIf="domain"><img [src]="index | imageUrl: defaultImg"></div>
<div *ngIf="!domain"><img src="{
{index}}"></div>
</div>
</nz-carousel>
<nz-carousel *ngIf="!init" #carousel [nzEffect]="effect" [nzDots]="false"
[nzAutoPlaySpeed]="0">
<div class="go" nz-carousel-content *ngFor="let index of array">
<div *ngIf="domain"><img [src]="index | imageUrl: defaultImg"></div>
<div *ngIf="!domain"><img src="{
{index}}"></div>
</div>
</nz-carousel>
</nz-content>
// ts代码 设置标识符,通过标识符来更改显示的组件
export class LoginComponent implements OnInit {
public init: boolean = false;
...... // 其他代码
ngOnInit() {
// 请求信息
this.systemSetupService.getSystemInfoByDomainName().then(data => {
const info: any = data;
this.init = true;
.... // 其他代码
})
}
}