为什么会出现此错误-在产品构建中使用ng2-bootstrap-modal时,“无法读取未定义的属性'0'"? [英] why get this error - 'Cannot read property '0' of undefined' when use ng2-bootstrap-modal in prod build?

查看:80
本文介绍了为什么会出现此错误-在产品构建中使用ng2-bootstrap-modal时,“无法读取未定义的属性'0'"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有angular 4项目,并且我使用的是ng2-bootstrap-modal,在调试模式下的对话框工作正常,但是当我以生产模式构建时,启动已发布的应用程序并单击按钮以显示对话框,出现此错误:

I have angular 4 project, and I'm using ng2-bootstrap-modal, in debug mode dialog works fine, but when I build in prod mode, start published application and click button to show dialog, get this error:

Cannot read property '0' of undefined
    at t.createDialogHolder (dialog.service.js.pre-build-optimizer.js:52)
    at t.addDialog (dialog.service.js.pre-build-optimizer.js:33)

如何解决此问题?

推荐答案

我更改dialog.service,这是

I change dialog.service, this:

 let componentRootViewContainer = this.applicationRef['_rootComponents'][0];

通过

let componentRootViewContainer = this.applicationRef.components[0];

这里是整个对话框,只需复制并粘贴即可: https://ufile.io/m8qm2

Here is whole dialog, just copy and paste it: https://ufile.io/m8qm2

in app.module
import { BootstrapModalModule } from './shared/dialog/bootstrap-modal.module';


imports: [
.....
    BootstrapModalModule,
....
]

这篇关于为什么会出现此错误-在产品构建中使用ng2-bootstrap-modal时,“无法读取未定义的属性'0'"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆