User61956409 posted
Hi comicrage,
However, instead of a button on the webpage, I need to invoke the modal popup from my navbar routerlink which are located in my header.component.html.
In your code, we can find that the modal would be triggered by clicking the button. If you'd like to show the modal while user click the routerLink, you can try to put the bootstrap modal in header.component.html and open it in routerLink
onClick() event.
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
</div>
<ng-template #content let-c="close" let-d="dismiss">
<div class="modal-header">
<h4 class="modal-title" id="modal-basic-title">Hi there!</h4>
<button type="button" class="close" aria-label="Close" (click)="d('Cross click')">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<p>Hello, World!</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-outline-dark" (click)="c('Save click')">Save</button>
</div>
</ng-template>
<!-- <button #mybutton class="btn btn-lg btn-outline-primary" (click)="open(content)">Launch demo modal</button> -->
<br/>
<br/>
<a routerLink = "login" (click)="rtlclick(content)">Login Component</a>
<br/>
<br/>
<br/>
<router-outlet></router-outlet>
In header.component.ts:
constructor(config: NgbModalConfig, private modalService: NgbModal) {
// customize default values of modals used by this component tree
config.backdrop = 'static';
config.keyboard = false;
}
rtlclick = function(content) {
this.modalService.open(content);
};
Test Result:

With Regards,
Fei Han