如何解决在 Angular 中使用 ComponentFactory 时,CSS 未加载到服务器上,但在 localhost 上工作正常
我正在使用 ComponentFactory 打开一个在本地主机上加载 CSS 的新窗口
但是当我在服务器上部署它时,我没有加载任何 CSS 或引导程序:
documentList: any;
OpenWindow: any;
constructor(private fb: FormBuilder,private router: Router,private resolver: ComponentFactoryResolver,private injector: Injector,private appRef: ApplicationRef) { }
viewDocument(docType) {
this.opendocumentWindow(DocumentDetailsComponent,'documentList',docType)
}
opendocumentWindow(component,list,data) {
const componentFactory = this.resolver.resolveComponentFactory(component);
let componentRef = componentFactory.create(this.injector);
this.appRef.attachView(componentRef.hostView);
this.OpenWindow = window.open('','','width=900,height=600,left=200,top=100');
this.OpenWindow.document.body.innerHTML = "";
document.querySelectorAll('link,style').forEach(htmlElement => {
this.OpenWindow.document.head.appendChild(htmlElement.cloneNode(true));
});
this.OpenWindow.document.body.appendChild(componentRef.location.nativeElement);
componentRef.instance[list] = [data];
}
解决方法
首先,我对 Angular 或 ComponentFactory 不是特别熟悉,但我确实遇到了 react 和语义 react 的确切问题,它在本地主机上的 dev 和 prod 版本上都可以正常工作,但省略了类似的问题给你部署,经过相当多的打击后,我尝试通过直接使用语义提供的 CDN 导入 css 来修复它,你的引导部分工作正常,无需通过 CDN 导入类。 >
我可能错了,但可能想检查它是否与我的问题类似。
祝你好运
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。