angular - How to know if Angular 7 component is currently loaded without using a timeout and no function on navigation
问题描述
I am trying to find a way to check if an Angular component is loaded on the page without using a timeout. Is there any way to do this? Edit: I cannot use AfterViewInit because I have an additional primeng component that it doesn't take into account.
解决方案
Depending on your use case a sure fire way could be to check if an element from the primeng component is visible on the page by using an interval something like this
primeNgInterval: any;
loaded = false;
// ...
checkForPrimeNgLoad() {
this.primeNgInterval = setInterval(() => {
let element = document.querySelector('#element');
if (element) {
loaded = true;
clearInterval(this.primeNgInterval);
}
}, 500);
}
推荐阅读
- android - 在更新的应用程序版本中删除其类的计划作业会发生什么情况
- r - 如何在R中分别以科学形式获得它的数量和权力?
- java - 错误:选择不包含主要类型
- android - 膨胀视图在 MVVM 设计模式中是如何工作的?
- javascript - javascript:拖动路径元素使其不可用
- javascript - Google 自定义搜索引擎标记的 Gatsby 错误
- xquery - xquery 属性等于带有空格的 id
- python - 将项目拆分为模块的 Pythonic 方式?
- android - 如何通过将项目添加到微调器中来对项目进行排序?
- swift - 如何制作正确过滤本地字符的 NSPredicate?