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

相关内容

热门资讯

交流学习经验!aapoker透... 1、交流学习经验!aapoker透视脚本入口,fishpoker透视底牌,科技教程(有挂软件)。2、...
技术分享!pokemmo手机辅... 技术分享!pokemmo手机辅助软件,hhpoker有没有外挂,攻略教程(有挂技巧);建议优先通过p...
玩家必看教程!wepoker免... 玩家必看教程!wepoker免费脚本,德州hhpoker是真的吗,技巧教程(有挂软件);德州hhpo...
记者揭秘!wpk官网下载链接,... 记者揭秘!wpk官网下载链接,wepoker怎么拿到好牌,解密教程(有挂辅助)是由北京得wepoke...
热门推荐!wepoker透视脚... 热门推荐!wepoker透视脚本网页,wpk插件辅助,教你攻略(有挂教程);建议优先通过wepoke...
盘点一款!哈糖大菠萝万能挂,菠... 盘点一款!哈糖大菠萝万能挂,菠萝辅助器免费版的功能介绍,专业教程(有挂透视);1.菠萝辅助器免费版的...
热门推荐!hhpoker一直输... 热门推荐!hhpoker一直输有挂吗,wepoker破解器,透牌教程(有挂神器);科技安装教程;13...
我来向大家传授!wepoker... 我来向大家传授!wepoker游戏的安装教程,德普之星有透视辅助吗,黑科技教程(有挂辅助);致您一封...
一起来探讨!德州局HHpoke... 一起来探讨!德州局HHpoker透视脚本,wepoker手机版透视脚本,技巧教程(有挂辅助)1、点击...
玩家必看秘籍!hhpoker真... 玩家必看秘籍!hhpoker真的有透视吗,hhpoker辅助靠谱吗,微扑克教程(有挂技巧);实战中需...