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

相关内容

热门资讯

透视总结!微扑克ai辅助器苹果... 透视总结!微扑克ai辅助器苹果版,智星德州菠萝辅助,一贯存在有挂(详细辅助攻略教程);1、游戏颠覆性...
透视私人局!aapoker有猫... 透视私人局!aapoker有猫腻,wepoke游戏数据有说法吗,确实有挂(详细辅助攻略教程)1、首先...
透视线上!aapoker透明挂... 透视线上!aapoker透明挂,德州ai辅助代理,好像是真的有挂(详细辅助必胜教程)1、下载好aap...
透视辅助!微扑克ai机器人,w... 透视辅助!微扑克ai机器人,wepoke保险,总是真的是有挂(详细辅助2025新版技巧);1、完成微...
透视了解!微扑克德州专用辅助器... 透视了解!微扑克德州专用辅助器,wpk俱乐部怎么盈利,原来真的是有挂(详细辅助教你攻略)暗藏猫腻,小...
透视数据!aapoker辅助工... 透视数据!aapoker辅助工具存在,wepoke机制,一贯真的有挂(详细辅助高科技教程);运aap...
透视神器!wepoke辅助挂,... 透视神器!wepoke辅助挂,德州手机辅助软件,一直真的是有挂(详细辅助系统教程)1、游戏颠覆性的策...
透视讲解!wepoke插件,a... 透视讲解!wepoke插件,aa扑克用模拟器,一贯是真的有挂(详细辅助揭秘教程);该软件可以轻松地帮...
透视黑科技!德州之星有外挂,w... 透视黑科技!德州之星有外挂,wpk线上德州俱乐部,果然是有挂(详细辅助wpk教程)1)德州之星有外挂...
wepokeai机器人(透视)... wepokeai机器人(透视)wepoke有没有玄学(详细辅助新2025版)确实是有挂(可靠辅助德之...