angular - 为什么 cdk-overlay-container 没有添加到另一个 DOM 位置?
问题描述
我试图改变cdk-overlay-container
放置的位置:
@Injectable({ providedIn: 'root' })
export class CustomOverlayContainer extends OverlayContainer {
constructor(@Optional() @Inject(DOCUMENT) _document: any) {
super(_document);
this._createContainer();
}
getContainerElement() {
return this._containerElement;
}
protected _createContainer(): void {
const containerClass = 'cdk-overlay-container';
const previousContainers = document.getElementsByClassName(containerClass);
// If there is already a container (can happen in a Microfrontend scenario with
// multiple self-contained Angular apps on the same website), reuse that. But
// clean it up because it could be created while transitioning from server
// to client (Angular Universal) and may be stale. Remove any additional containers.
for (let i = 0; i < previousContainers.length; i++) {
while (i === 0 && previousContainers[i].firstChild) {
previousContainers[i].removeChild(previousContainers[i].firstChild);
}
if (i > 0 && !!previousContainers[i].parentNode) {
previousContainers[i].parentNode.removeChild(previousContainers[i]);
}
}
if (previousContainers.length > 0) {
this._containerElement = previousContainers[0] as HTMLElement;
return;
}
const container = document.createElement('div');
container.classList.add(...[containerClass, 'ss']);
let c = document.getElementById('map');
c.appendChild(container);
this._containerElement = container;
}
}
然后我在根模块中使用它,如下所示:
{ provide: OverlayContainer, useExisting: CustomOverlayContainer },
无论如何,容器cdk-overlay-container
被放置在身体中document.getElementById('map');
。
解决方案
推荐阅读
- scala - 使用 scala 和 maria db 的简单 curd rest api
- python - 如何在进程终止后等待,直到使用 Python 在 Windows 上解锁文件?
- dart - 如何创建一个有 2 列的表以在颤动中显示数据?一列具有静态数据,另一列具有可编辑的空字段
- c++ - 使用 C++ 将 IP 地址附加到 char*
- c# - System.EntryPointNotFoundException 即使在 c# 代码中指定入口点(函数名)之后
- android - Android 合并 2 个数据列表,一个来自 Room LiveData,另一个来自 Observable
- jquery - $.fn.DataTable.render.text 不是函数
- datepicker - ag-Grid 中的日期选择器不起作用
- java - 从rest api返回非常大的数据
- python - 如何检查字符串是否包含图像?