Reputation: 4142
I'm trying to implement NgbModal into my code, but I keep getting the same error: 'ngbd-modal-component' is not a known element.
It's probably something stupid I forgot, but I'm breaking my head over this. Can someone point me in the right direction?
Core.module
import { NgModule, Optional, SkipSelf } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NgSelectModule } from '@ng-select/ng-select';
import { NgbModule, NgbModalModule } from '@ng-bootstrap/ng-bootstrap';
import { NavComponent } from './components/nav/nav.component';
import { SpinnerComponent } from './shared/components/spinner/spinner.component';
import { LoggerService } from './services/logger.service';
import { throwIfAlreadyLoaded } from './guards/module-import.guard';
import { NgbdModalComponent, NgbdModalContent } from './shared/components/config-modal/config-modal.components';
@NgModule({
imports: [
CommonModule,
FormsModule,
NgSelectModule,
NgbModalModule,
NgbModule.forRoot()
],
entryComponents: [NgbdModalContent],
exports: [NavComponent, FormsModule],
declarations: [NavComponent, SpinnerComponent, NgbdModalComponent, NgbdModalContent],
providers: [LoggerService]
})
export class CoreModule {
constructor( @Optional() @SkipSelf() parentModule: CoreModule) {
throwIfAlreadyLoaded(parentModule, 'CoreModule');
}
}
Component
import { Component, Input } from '@angular/core';
import { NgbModal, NgbActiveModal } from '@ng-bootstrap/ng-bootstrap';
@Component({
selector: 'ngbd-modal-content',
template: `
<div class="modal-header">
<button type="button" class="close" aria-label="Close" (click)="activeModal.dismiss('Cross click')">
<span aria-hidden="true">×</span>
</button>
<h4 class="modal-title">Hi there!</h4>
</div>
<div class="modal-body">
<p>Hello, {{name}}!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" (click)="activeModal.close('Close click')">Close</button>
</div>
`
})
export class NgbdModalContent {
@Input() name;
constructor(public activeModal: NgbActiveModal) { }
}
@Component({
selector: 'ngbd-modal-component',
templateUrl: 'src/lazy/modal-component.html'
})
export class NgbdModalComponent {
constructor(private modalService: NgbModal) { }
open() {
const modalRef = this.modalService.open(NgbdModalContent);
modalRef.componentInstance.name = 'World';
}
}
Upvotes: 1
Views: 1059
Reputation: 10303
Add it to your exports in the core.module:
exports: [NavComponent, FormsModule, NgbModalModule],
EDIT
Sorry I didn't realize NgbdModalComponent was a custom component. Try exporting it instead of the module:
exports: [NavComponent, FormsModule, NgbdModalComponent],
Upvotes: 2