Closed ajcastro closed 6 years ago
I think I have a similar setup.
I have a ModalComponent class defined with this as the @Component which
selector: 'my-modal',
this inside the component class in the declarations
@ViewChild('myModal')
modal: BsModalComponent;
resolve: (z: any) => void;
reject: (z: any) => void;
and a method on the class like this
open(): Promise<any> {
return new Promise<any>((resolve, reject) => {
this.resolve = resolve;
this.reject = reject;
this.modal.open();
});
}
and this is in the html
<bs-modal #myModal [size]='"lg"' (onDismiss)="close()">
Then on the page that includes it
@ViewChild(ModalComponent)
myModal: ModalComponent;`
and in the pages html i simply have
<my-modal ></my-modal>
when i want to open it in the main page component is call
this.myModal.open()
which returns the Promise that will be used when the modal is closed to inform the parent component things are done.
Inside the modal component i have access to this.resolve(...)
and this.reject(...)
to control how i notify back up
@donsutherland thanks.. you're right.. I have a simpler setup..
What I did.
parent_main.component.html
<my-modal #myModal></my-modal> // assign template reference variable myModal
<button (click)="myModal.open()"> Open Modal </button> // open() method of MyModalComponent
MyModalComponent
@ViewChild('modal')
public modal: BsModalComponent;
public open() {
this.modal.open('lg');
}
Sure that makes sense. In my use case I needed to control it from inside the code and was passing some additional info inward, so needed the extra wiring for such.
Glad you got it working.
Hello. I am not sure if this right place to go but I just need help, an example how can I create a modal component out of the ng2-bs3-modal. I need to create a component named
auth-modal
. So I have a component fileauth-modal.component.ts
and and its html fileauth-modal.component.html
auth-modal.component.html
seems to look like this but not the actual html codeThe
auth-modal.component.ts
looks like a very usual component where it will handle submission of the form.Then I have the main html or component lets say
main.component.html
andmain.component.ts
where there is a button "Show Auth Form Modal", and this will trigger the showing of theauth-modal
. So how am I going to achieve that?My idea is something like this
main.component.html
main.component.ts