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、让任何用...
透视私人局!pokermast... 透视私人局!pokermaster修改器(透视)邳州友友辅助(其实有辅助软件)-哔哩哔哩1、许多玩家...
透视了解!we poker插件... 透视了解!we poker插件(透视)福建宁德麻将辅助软件(切实存在有辅助工具)-哔哩哔哩1、每一步...
做出回应!wepoker脚本(... 做出回应!wepoker脚本(透视)微信小程序游戏破解器(果然是真的辅助安装)-哔哩哔哩1、起透看视...
透视插件!德州局脚本(透视)友... 透视插件!德州局脚本(透视)友间十三道有什么窍门(原来真的有辅助插件)-哔哩哔哩1、友间十三道有什么...
此事迅速冲上热搜!wepoke... 此事迅速冲上热搜!wepoker怎么增加运气(透视)微友助手怎么破解(真是有辅助app)-哔哩哔哩微...
透视玄学!aapoker怎么设... 透视玄学!aapoker怎么设置抽水(透视)边锋干橙眼辅助器下载(都是是有辅助平台)-哔哩哔哩1、边...
透视挂!xpoker透视辅助(... 透视挂!xpoker透视辅助(透视)天天贵阳大瓮安插件(好像真的有辅助app)-哔哩哔哩1、完成天天...
刚刚!hh poker辅助有用... 刚刚!hh poker辅助有用吗(透视)海盗来了辅助器无限炮(一贯真的是有辅助安装)-哔哩哔哩1、超...
据文件显示!德普之星私人局透视... 据文件显示!德普之星私人局透视(透视)反杀新大厅辅助(切实真的有辅助修改器)-哔哩哔哩暗藏猫腻,小编...