Angular叠加层错误将非现有DOM元素视为覆盖层容器。
创始人
2024-10-24 12:01:40
0次

这个问题通常是由于在应用中没有正确配置覆盖层容器而引起的。为了解决此问题,可以使用Angular的Overlay服务的create方法来创建一个覆盖层容器,并将其附加到现有的DOM元素。例如:

在组件中创建一个ViewContainerRef和OverlayRef:

import { Component, ViewChild, OnInit, OnDestroy } from '@angular/core'; import { Overlay, OverlayRef } from '@angular/cdk/overlay'; import { ComponentPortal } from '@angular/cdk/portal';

@Component({ selector: 'app-example-overlay', template: , }) export class ExampleOverlayComponent implements OnInit, OnDestroy { @ViewChild('overlayHost') overlayHost: ElementRef; private overlayRef: OverlayRef;

constructor(private overlay: Overlay) {}

ngOnInit() { const positionStrategy = this.overlay .position() .global() .centerHorizontally() .centerVertically();

this.overlayRef = this.overlay.create({
  hasBackdrop: true,
  positionStrategy,
});

}

ngOnDestroy() { this.overlayRef.dispose(); }

showOverlay() { const portal = new ComponentPortal(SomeOverlayComponent); const componentRef = this.overlayRef.attach(portal); // 让覆盖层包含组件的区域 componentRef.instance.overlayHost = this.overlayHost; } }

在覆盖层组件中添加一个Input属性:

import { Component, Input } from '@angular/core';

@Component({ selector: 'app-some-overlay', template:

, }) export class SomeOverlayComponent { @Input() overlayHost: ElementRef; constructor() {}

ngOnInit() { const nativeElement = this.overlayHost.nativeElement; // 将overlayContent附加到overlay

相关内容

热门资讯

分享实测!微扑克透视脚本,德普... 『标题:当前标题』主打赛后复盘的 AI 游戏攻略黑科技走红,对局总结能力开挂。上传对局回放或者战绩截...
玩家亲测!WPK作弊,WPK开... 『标题:当前标题』主打赛后复盘的 AI 游戏攻略黑科技走红,对局总结能力开挂。上传对局回放或者战绩截...
重要通知!wpk透视辅助方法,... 重要通知!wpk透视辅助方法,wepoker是不是有挂脚本(好像是真的有透视)主打本地运行的 AI ...
玩家必备科技!wepoker辅... 您好:wepoker辅助工具这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
推荐一款!WPK透视版,wep... 一款 AI 游戏攻略黑科技工具上线,查攻略效率直接开挂。它整合版本更新、装备搭配、BOSS 打法、牌...
终于懂了!!wpk有没有脚本,... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成wpk有没有脚本解析、 AI 处理、...
详细教程!wejoker辅助软... 您好:wejoker辅助软件视频这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很...
一分钟带你了解!wepoker... 本地部署 AI 黑科技工具迎来新版本,不用上传文件到云端就能完成wepoker透视脚本解析、 AI ...
盘点十款!wpk有没有脚本,W... 您好:wpk有没有脚本这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
揭秘关于!wepoker有什么... 您好:wepoker有什么规律这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多...