我添加到了我的角度项目NG2-引导模式,并遵循了在这个url:https://www.npmjs.com/package/ng2-bootstrap-modal中重新编写的步骤。
在我出版之前,Everiting运作良好,代码是与webpack一起“编译”成FAT env的。据我所知,它不能创建对话框持有人。
我深入研究了模态代码,发现错误出现在dialog.service.js的“dialog.service.js”中。
组件中的原始代码如下所示:
DialogService.prototype.createDialogHolder = function () {
var _this = this;
var componentFactory = this.resolver.resolveComponentFactory(dialog_holder_component_1.DialogHolderComponent);
var componentRef = componentFactory.create(this.injector);
var componentRootNode = componentRef.hostView.rootNodes[0];
if (!this.container) {
var componentRootViewContainer = this.applicationRef['_rootComponents'][0];
this.container = componentRootViewContainer.hostView.rootNodes[0];
}
this.applicationRef.attachView(componentRef.hostView);
componentRef.onDestroy(function () {
_this.applicationRef.detachView(componentRef.hostView);
});
this.container.appendChild(componentRootNode);
return componentRef.instance;
};webpack“编译”后的代码如下:
t.prototype.createDialogHolder = function() {
var t = this
, e = this.resolver.resolveComponentFactory(u.DialogHolderComponent)
, n = e.create(this.injector)
, r = n.hostView.rootNodes[0];
if (!this.container) {
var o = this.applicationRef._rootComponents[0];
this.container = o.hostView.rootNodes[0]
}
return this.applicationRef.attachView(n.hostView),
n.onDestroy(function() {
t.applicationRef.detachView(n.hostView)
}),
this.container.appendChild(r),
n.instance
}这一错误是一致的:
var o = this.applicationRef._rootComponents[0];因为_rootComponents是空的。
你知道怎么修吗?注意:代码与上面的链接100%相同。
Upd:在app.module.ts中,我尝试使用默认容器以及特定容器BootstrapModalModule.forRoot({ BootstrapModalModule.forRoot: document.body })导入BootstrapModalModule
发布于 2018-05-11 10:07:45
以下答案对普通bootstrap有效。但是,由于ngx-bootstrap (a.k.a ng2-bootstrap)是构建在普通引导带之上的,所以它可能仍然是相关的。
我注意到,在.angular-cli.json文件中导入.angular-cli.json,正如在ngx上推荐的那样,在dev模式下工作,但一旦使用webpack编译,就不能工作了。
在src/styles.css文件中导入引导程序,就像在this post中为我做的那样。
发布于 2019-10-02 12:34:19
当您从角4移到5+时,我们只需要添加几行来解决整个项目的这个问题。希望这对仍在寻找解决方案的人有所帮助。
https://stackoverflow.com/questions/50288187
复制相似问题