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

相关内容

热门资讯

此事引发广泛关注!智星德州有脚... 此事引发广泛关注!智星德州有脚本吗,哈糖大菠萝助手,学习教程(确实有挂)-哔哩哔哩1、智星德州有脚本...
更值得关注的是!hhpoker... 更值得关注的是!hhpoker脚本下载(透视)果然确实有挂(揭秘有挂开挂辅助插件)-哔哩哔哩1、起透...
据统计!智星菠萝可以辅助吗,n... 据统计!智星菠萝可以辅助吗,newpoker怎么安装脚本,阶段教程(有挂透视)-哔哩哔哩1、起透看视...
据监测!pokemmo免费脚本... 据监测!pokemmo免费脚本(透视)原来确实有挂(揭秘有挂开挂辅助工具)-哔哩哔哩1、pokemm...
据通报!wepoker轻量版透... 据通报!wepoker轻量版透视方法,wepoker俱乐部辅助,模板教程(有挂技巧)-哔哩哔哩1、打...
据权威媒体报道!wepoker... 据权威媒体报道!wepoker手机助手(透视)一直是有挂的(有挂教学开挂辅助工具)-哔哩哔哩在进入w...
围绕透视问题!wepoker透... 围绕透视问题!wepoker透视辅助下载,智星菠萝有挂吗,攻略教程(有挂辅助)-哔哩哔哩1、进入到w...
据玩家消息!pokemmo免费... 据玩家消息!pokemmo免费脚本(透视)一直有挂(有挂总结开挂辅助神器)-哔哩哔哩1、让任何用户在...
目前!poker辅助器免费安装... 目前!poker辅助器免费安装,德州局透视脚本,模板教程(今日头条)-哔哩哔哩1、让任何用户在无需p...
记者获悉!wpk辅助购买(透视... 记者获悉!wpk辅助购买(透视)一直是有挂(有挂解惑开挂辅助安装)-哔哩哔哩一、wpk辅助购买软件透...