Topic: Angular 2 Modal Directive Error with exportAs
Orestes Garcia asked 7 years ago
I\\\'m trying to reproduce in my project one of your modal examples, but I\\\'m getting this error:Uncaught Error: Template parse errors:There is no directive with \\\"exportAs\\\" set to \\\"bs-modal\\\" (\\\"ick)=\\\"show( \\\'@getbootstrap\\\' )\\\" ripple-radius>Open modal for @getbootstrap</button>
This is my component:
import { Component, ViewChild } from \\\'@angular/core\\\';
import { ModalDirective
} from
'../../mdb/free/modals'; @Component({ selector: \\\'modal-content-example\\\', templateUrl: \\\'modal-content.html\\\',}) export class ModalContentComponent { @ViewChild(\\\'content\\\') public contentModal; public name: string; show(value:string){ this.name = value; this.contentModal.show(); }}
This is my html:
Also, in my app.module I imports:
Please, any idea, what is causing my error?
Thanks in advance.
Edyta Dabrowska answered 7 years ago
@ViewChild('content') public contentModal;
public name: string;
show(value:string){
this.name = value;
this.contentModal.show();
}
to your app.component.ts inside export class AppComponent {}
. But you need to remember to add 'ViewChild' like this: import { Component, ViewChild } from '@angular/core';
. Orestes Garcia commented 7 years ago
Hi Edyta, Thanks for your answer, Yes, I created a new component for the modal. the idea is to reuse the modal component for different features in my app. I could fix the error by importing and exporting MDBBootstrapModule in a GlobalModule NgModule that I created for all my reusable components. Also, because the button that trigers the modal belongs to other component I have to declare the bsModal Directive on the modal selector this way => Then I'm using angular content projection in my modal component. This way the content of the modal can switch depending on what you want to show. <div> <pre><!-- Global Empty Modal --> <div class="modal-dialog modal-full-height modal-left" role="document"> <divclass="modal-content"> <divclass="modal-header"> <ng-contentselect=".app-modal-header"></ng-content> </div> <divclass="modal-body"> <ng-contentselect=".app-modal-body"></ng-content> </div> <divclass="modal-footer"> <ng-contentselect=".app-modal-footer"></ng-content> </div> </div> </div> <!-- Modal --></pre> </div> <!-- Global Empty Modal --> <!-- Modal -->FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Resolved
- User: Free
- Premium support: No
- Technology: MDB Angular
- MDB Version: -
- Device: -
- Browser: -
- OS: -
- Provided sample code: Yes
- Provided link: No