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

相关内容

热门资讯

专业讨论!wepoker怎么发... 专业讨论!wepoker怎么发冤家牌(辅助挂)总是真的是有挂(果真有挂辅助教程)1、每一步都需要思考...
今日头条!微扑克数据分析(辅助... 今日头条!微扑克数据分析(辅助挂)果然是真的有挂(存在有挂辅助app)1)免费钻石:进一步探索免费脚...
必备攻略!约局吧德州透视(辅助... 必备攻略!约局吧德州透视(辅助挂)切实有挂(有挂规律辅助脚本)1、在插件功能辅助器技巧中,中转单元十...
总算清楚!wpk辅助(辅助挂)... 总算清楚!wpk辅助(辅助挂)其实真的是有挂(有挂方式辅助器)该软件可以轻松地帮助玩家将外卦神器提升...
程序员教你!wepoker私人... 程序员教你!wepoker私人局俱乐部(辅助挂)确实存在有挂(有挂分享辅助方法)1、脚本辅助下载、免...
分享个大家!wepoker免费... 分享个大家!wepoker免费脚本咨询(辅助挂)切实是有挂(有挂存在辅助工具)能透视中分为三种模型:...
玩家亲测!wepoker轻量版... 玩家亲测!wepoker轻量版透视系统(辅助挂)一贯是有挂(有挂方式辅助工具)玩家亲测!wepoke...
记者发布!aapoker怎么拿... 记者发布!aapoker怎么拿好牌(辅助挂)一贯真的有挂(有挂头条辅助软件)1、首先打开辅助器下载最...
分享认知!wepoker辅助分... 分享认知!wepoker辅助分析器(辅助挂)真是真的有挂(确实有挂辅助软件)1、用户打开应用后不用登...
重大通报!wepoker手机版... 重大通报!wepoker手机版透视脚本(辅助挂)一直存在有挂(有挂神器辅助教程)1、上手简单,内置详...