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怎么获得好牌,wpk透视辅助,本来真的有挂(有挂教程)1、辅助软件下载优化,...
攻略辅助挂!aapoker怎么... 攻略辅助挂!aapoker怎么拿好牌,德扑之星有辅助软件吗,其实是有挂(有挂头条)1、全新机制【德扑...
科技通报!wepoker私人定... 科技通报!wepoker私人定制透视,wepoker插件功能辅助器,好像真的有挂(有挂详细)1、免费...
事发当天!wepoker开脚本... 事发当天!wepoker开脚本视频,德普之星透视辅助插件,竟然是有挂(今日头条)1、这是跨平台的德普...
这一问题亟待解决!wepoke... 这一问题亟待解决!wepoker私人局透视,德普之星透视辅助软件下载,一贯是有挂(有挂技巧)1、起透...
玩家必用!wepoker破解版... 玩家必用!wepoker破解版内购,hhpoker是真的吗,其实真的有挂(有挂讲解)1、上手简单,内...
2026版教学!hhpoker... 2026版教学!hhpoker怎么防作弊,德普之星辅助软件,原来真的有挂(有挂攻略)1、超多福利:超...
记者揭秘!智星德州插件,pok... 记者揭秘!智星德州插件,pokemmo脚本辅助器下载,竟然有挂(有挂讲解)1)免费钻石:进一步探索免...
截至发稿!德州透视插件,德普之... 截至发稿!德州透视插件,德普之星透视辅助软件是真的吗,一直真的是有挂(有挂教程)1、玩家可以在德普之...
一分钟揭秘!poker wor... 一分钟揭秘!poker world辅助器,哈糖大菠萝有挂吗,一贯是有挂(有挂存在)1、游戏颠覆性的策...