Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught Error: Can't resolve all parameters for 'ComponentName': ([object Object], ?)

I dont know why I am getting the error

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>)

I am trying to use ngbModal and here is what i have done so far.

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>

and .ts file

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"
    ]

Counting on ya'll! Please ask if any more clarification is needed.

like image 709
MenimE Avatar asked Mar 12 '26 22:03

MenimE


2 Answers

You need to import it in your NgModule instead of injecting it in your component.

import { ModalModule } from 'ngb-modal';

@NgModule({
  imports: [
    ...
    ModalModule,
  ],

Remove private modalService: NgbModal from the constructor:

constructor(private service : OfferClauseService,private modalService: NgbModal) { }

And instead add 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();
    }
}

Reference: https://www.npmjs.com/package/ngb-modal

like image 99
ulmas Avatar answered Mar 15 '26 10:03

ulmas


You need to add your dialog component into entryComponents in your module.

@NgModule({
  declarations: [
    AppComponent, ModalComp
  ],
  imports: [
    ...
    ModalModule,
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [ModalComp]
})
like image 40
Taras Kovalenko Avatar answered Mar 15 '26 11:03

Taras Kovalenko



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!