我不知道为什么会收到错误
compiler.js:2175 Uncaught Error: Can't resolve all parameters for ClauseListComponent: ([object Object], ?).
at syntaxError (compiler.js:2175)
at CompileMetadataResolver._getDependenciesMetadata (compiler.js:20399)
at CompileMetadataResolver._getTypeMetadata (compiler.js:20294)
at CompileMetadataResolver.getNonNormalizedDirectiveMetadata (compiler.js:19923)
at CompileMetadataResolver._getEntryComponentMetadata (compiler.js:20494)
at compiler.js:20486
at Array.forEach (<anonymous>)
at CompileMetadataResolver._getEntryComponentsFromProvider (compiler.js:20485)
at compiler.js:20456
at Array.forEach (<anonymous>)
我正在尝试使用ngbModal,这是我到目前为止所做的。
clause.module.ts
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
@NgModule({
declarations: [ModuleListComponent,ClauseListComponent,ModifyClauseComponent],
imports: [
NgbModule
clauselist.html
<ng-template #content let-modal >
<div class="modal-header">
<h4 class="h4Header" id="modal-basic-title">Title</h4>
<button type="button" class="close" aria-label="Close" (click)="modal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
CheckMate!
</div>
<div class="modal-footer">
<button mat-flat-button class="text-btn" (click)="modal.close('Save click')">ENROLL NOW</button>
<button mat-flat-button class="text-btn" (click)="modal.close('Save click')">Later</button>
</div>
</ng-template>
<button mat-flat-button class="primary-btn marR16" (click)="open(content)">Modal dialog</button>
和 .ts文件
import {NgbModal} from '@ng-bootstrap/ng-bootstrap';
constructor(private service : OfferClauseService,private modalService: NgbModal) { }
open(content) {
this.modalService.open(content,{windowClass:'custom_modal'})
}
tsconfig
"lib": [
"es2018",
"dom"
]
指望你们!请询问是否需要进一步澄清。
答案 0 :(得分:2)
您需要将其导入NgModule中,而不是将其注入组件中。
import { ModalModule } from 'ngb-modal';
@NgModule({
imports: [
...
ModalModule,
],
从构造函数中删除private modalService: NgbModal
:
constructor(private service : OfferClauseService,private modalService: NgbModal) { }
并添加ModalManager
:
export class YourComponent {
@ViewChild('myModal') myModal;
private modalRef;
constructor(private modalService: ModalManager){}
openModal(){
this.modalRef = this.modalService.open(this.myModal, {
...
})
};
...
closeModal(){
this.modalService.close(this.modalRef);
//or this.modalRef.close();
}
}
答案 1 :(得分:1)
您需要将对话框组件添加到模块的entryComponents
中。
@NgModule({
declarations: [
AppComponent, ModalComp
],
imports: [
...
ModalModule,
],
providers: [],
bootstrap: [AppComponent],
entryComponents: [ModalComp]
})