Open ng-bootstrap modal programmatically

前端 未结 2 720
暖寄归人
暖寄归人 2020-12-15 19:42

I\'ve got an angular 4 page including a ng-bootstrap modal. My code looks like this.

foo.html

[...]
相关标签:
2条回答
  • 2020-12-15 19:55

    from Angular 8 you should also pass static option: {static: false} in ViewChild

    import { ViewChild } from '@angular/core';
    
    @ViewChild('content', { static: false }) private content;
    
    constructor(private modalService: NgbModal) { }
    
    this.modalService.open(this.content);
    
    0 讨论(0)
  • 2020-12-15 20:05

    To access the content element inside the class, declare:

    @ViewChild('content', { static: false }) private content;
                             ^for Angular8+
    

    and add the corresponding import at the top of the class:

    import { ViewChild } from '@angular/core';
    

    and finally call open method for that element on change detection:

    ngOnChanges(changes: any) {
       this.open(this.content);
    }
    
    0 讨论(0)
提交回复
热议问题