我想做这样的事情。当组件加载时,1 秒后加载它的 html。 这是代码组件 (ts)。
import { Component } from '@angular/core';
@Component({
selector: 'pagination',
templateUrl: './app/html/pagination.component.html',
styleUrls: ['app/css/pagination.component.css']
})
export class Pagination {}
我们在代码中看到templateUrl: './app/html/pagination.component.html',
1秒后怎么加载?
总的来说,我的想法包括在服务器上执行发布请求时为用户显示延迟加载(1 秒)。
有人有什么想法吗?
最佳答案
尝试使用 ngIf 指令。
所以它看起来像这样:
<div *ngIf="showContent">Will appear after ~1 sec</div>
在组件代码中:
export class Pagination {
public showContent: boolean = false;
public ngOnInit() {
setTimeout(()=>this.showContent=true, 1000);
}
}
关于angular - 延迟组件的html angular 2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39851933/