I'm trying to call a modal function in the constructor in Angular 4 but the function get highlighted that is not properly called and when the page is loaded not error is read in the log and the modal is not popping up as its suppose to. The screen gets dark alright but the text in the modal doesn't show up.
constructor(public formBuilder: FormBuilder,
public router: Router,
public toastr: ToastrService,
public http: HttpClient,
public modalService: BsModalService,) {
if (this.getWardData) {
this.displayHint();
}
}
displayHint(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, {class: 'modal-sm'});
}
HTML
<ng-template #template>
<div class="modal-body text-center">
<p>Do you want to Continue where you left?</p>
<button type="button" class="btn btn-default" (click)="confirm()" >Yes</button>
<button type="button" class="btn btn-primary" (click)="decline()" >No</button>
</div>
</ng-template>
Try to use the following code
constructor(public formBuilder: FormBuilder,
public router: Router,
public toastr: ToastrService,
public http: HttpClient,
public modalService: BsModalService, ) {
// if (this.getWardData) {
// this.displayHint();
// }
}
ngOnInit() {
if (this.getWardData) {
this.displayHint();
}
}
displayHint(template: TemplateRef<any>) {
this.modalRef = this.modalService.show(template, { class: 'modal-sm' });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With