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

相关内容

热门资讯

玩家必备科技!wpk模拟器是什... 玩家必备科技!wpk模拟器是什么,佛手在线有挂吗,原来是有挂(有人有挂)辅助器是一种具有地方特色的麻...
2分钟细说!哈糖大菠萝攻略,红... 2分钟细说!哈糖大菠萝攻略,红龙poker作弊指令,总是是有挂(有挂教程)1、破解器简单,机器人操作...
大家学习交流!wepoker透... 大家学习交流!wepoker透视脚本视频,wepoker辅助器有哪些功能,果然是有挂(真实有挂)1、...
推荐一款!wepoker私人局... 推荐一款!wepoker私人局俱乐部辅助,拱趴大菠萝十三水作弊,竟然真的有挂(有挂解惑)所有人都在同...
避坑细节!aapoker脚本,... 避坑细节!aapoker脚本,wepoker养号规律,原来存在有挂(有挂实锤)1、操作简单,无需手机...
重大通报!pokemmo脚本最... 重大通报!pokemmo脚本最新版,悟空黑桃a有挂嘛,其实有挂(有挂方略)1、重大通报!pokemm...
实测发现!pokemmo脚本最... 实测发现!pokemmo脚本最新版,悟空黑桃a有挂嘛,总是存在有挂(有挂辅助)1. 选牌创建新账号,...
玩家必看教程!wepoker辅... 玩家必看教程!wepoker辅助器最新版本更新内容,约局吧德州真的存在透视吗,确实是真的有挂(有挂分...
一分钟了解!wepoker透视... 一分钟了解!wepoker透视版下载,wepoker透视破解版,竟然存在有挂(有挂工具)1、金币登录...
终于懂了!hhpoker作弊码... 终于懂了!hhpoker作弊码,德普之星透视,竟然是有挂(有挂教程)1、首先打开辅助器下载最新版本,...