NgbModal calling open() from ngOnInit() opens a new tab

Hi,

I was testing with “Components as Content” example, and I think I found a bug. What I wanted to do was to open a dialog when this component was called. (I’m using angular router, and when the menu is selected, I want to open the dialog). So I implemented “OnInit”, and added ngOnInit() to NgbdModalComponent. Inside ngOnInit(), I simply called open(). When I ran, it just opened a new tab in Chrome and nothing happened. I tried to re-create this scenario on Plunker, maybe I’m wrong but I don’t think Plunker can show OnInit behavior. I was using the example you have for “Component as Content”, and simply added ngOnInit() to “NgbdModalComponent”.

Angular:
2.4.6
ng-bootstrap:
4.1.2
Bootstrap:
4.0.0-alpha.6

1 possible answer(s) on “NgbModal calling open() from ngOnInit() opens a new tab

  1. You’re calling open(), i.e. window.open(), in your ngOnInit() method. As documented, this opens a new tab. If you want to call the open() method of the component, then the syntax is this.open().

    Closing the issue.