【问题标题】:Illegal Invocation instantiating BS Modal非法调用实例化 BS 模态
【发布时间】:2021-05-16 10:34:36
【问题描述】:

我试图通过组件而不是使用它的 HTML 属性以角度调用引导模式。我收到一个错误(即非法调用)。

组件:

@ViewChild('myModal') div:any;

ngAfterViewInit() {let bs = new bootstrap.Modal(this.div);}

HTML

<div class="modal-content" #myModal>...</div>

【问题讨论】:

    标签: javascript angular typescript twitter-bootstrap


    【解决方案1】:

    您需要使用服务而不是创建它的实例。对代码进行这些更改:

    import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/ng-bootstrap';
    ...
    ...
    @ViewChild('myModal') div:any;
    
    constructor(private modalService: NgbModal )
    
    ngAfterViewInit() {
         // make sure you get the instance of the child.
         this.modalService.open(this.div);  
    }
    

    【讨论】:

      猜你喜欢
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-11
      相关资源
      最近更新 更多