【发布时间】:2018-02-14 23:30:51
【问题描述】:
当我尝试打开模式时,BsModalRef$$1 出现 NullInjector 错误。
我的 app.module.ts 如下
import { ModalModule } from 'ngx-bootstrap';
@NgModule({
imports: [BrowserModule, RouterModule, ModalModule.forRoot()],
...
我的 system.config.js 如下所示
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
'app': 'js',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
'@angular/upgrade/static': 'npm:@angular/upgrade/bundles/upgrade-static.umd.js',
'@angular/common/http': 'npm:@angular/common/bundles/common-http.umd.js',
'tslib': 'npm:tslib/tslib.js',
// other libraries
'rxjs': 'npm:rxjs',
'ngx-cookie-service': 'npm:ngx-cookie-service/cookie-service/cookie.service.js',
'ts': 'npm:plugin-typescript/lib',
'typescript': 'npm:typescript/lib/typescript.js',
'angular-scholarship-seed': 'npm:angular-scholarship-seed/bundles/angular-scholarship-seed.umd.js',
'angular-dpa-seed': 'npm:angular-dpa-seed/bundles/angular-dpa-seed.umd.js',
'ngx-bootstrap': 'npm:ngx-bootstrap/bundles/ngx-bootstrap.umd.js',
我在使用 ng-packagr 打包的不同 Web 应用程序中有一个组件。
我调用 BsModalRef 的组件大致如下
import {ActivatedRoute, RouterModule, Router} from '@angular/router';
import { BsModalService } from 'ngx-bootstrap';
import { BsModalRef } from 'ngx-bootstrap';
import { ModalContentComponent } from './athleticmodal/athletic.modal';
import { TemplateRef} from '@angular/core';
@Component({
selector: 'dummy-list',
})
export class DummyListComponent {
modalRef: BsModalRef;
getAcademicTermsByDate(){
this.modalRef = this.modalService.show(ModalContentComponent);
}
constructor(private modalService: BsModalService) { }
}
我正在使用 ng-packagr 打包这个和其他几个组件并将它们发布到 npm 并从我的 app.module.ts 所在的主 Web 应用程序中引用。
我在 ng-package.json 中添加了下面的外部语句
{
"$schema": "./node_modules/ng-packagr/ng-package.schema.json",
"lib": {
"entryFile": "public_api.ts",
"externals": {
"ngx-bootstrap": "ngx-bootstrap"
}
}
}
我尝试了很多方法来完成这项工作,例如更改外部名称、从“ngx-bootstrap/modal”导入 BsModalRef 以及类似
从 'ngx-bootstrap/modal/bs-modal-ref.service' 导入 { BsModalRef };
但是没有任何效果。有人可以帮我吗。
【问题讨论】:
标签: angular systemjs ngx-bootstrap