javascript - 如何从 Angular 2 的管道中附加动态 DOM 元素?
问题描述
我正在尝试从管道指令中附加一个垫子微调器,该指令应该在 | 时添加加载 异步正在执行
我有这个人要改造
transform(val: any): any {
this.showLoader();
return isObservable(val)
? val.pipe(
catchError((error) => of(this.hideLoader())),
finalize(() => this.hideLoader())
)
: val;
}
这对于显示加载程序:
showLoader(): void {
const componentFactory =
this.componentFactoryResolver.resolveComponentFactory<MatSpinner(MatSpinner);
const matSpinner = this.viewContainerRef.createComponent(componentFactory);
matSpinner.instance.diameter = 24;
this.progressElement = matSpinner.injector.get(MatSpinner)._elementRef.nativeElement;
this.renderer.appendChild(this.el.nativeElement, this.progressElement);
}
有什么建议可以克服这个问题吗?或者任何其他想法都会有所帮助。
ps:最终的产品应该是这样的<div *ngIf="data$ | loadingPipe | async> </div>
解决方案
推荐阅读
- c# - RavenDB 的 BulkInsert 错误:文档 ID 必须具有非空值
- symfony - Symfony 4 ROLE_USER 到 ROLE_ADMIN 与数据库
- java - 使用 iText 阅读 PDF 中以图像形式给出的复选框
- angular - 比较反应形式以仅过滤掉更新的值
- javascript - AWSIoT:AWSIoTShadowClient 与 AWSIoTMQTTClient
- android - Android Nougat 通知操作按钮未显示在通知中
- cors - 通过跨域重定向透明移动启用 CORS 的资源
- facebook-marketing-api - 使用他们的 API 检索过去一段时间的 Facebook 覆盖率?
- python - 通过代理使用 TLSv1.0 的 Scrapy 握手失败
- android-workmanager - 发现多个文件的操作系统独立路径为“META-INF/proguard/androidx-annotations.pro”