Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/379.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 实例化BS模式的非法调用_Javascript_Angular_Typescript_Twitter Bootstrap - Fatal编程技术网

Javascript 实例化BS模式的非法调用

Javascript 实例化BS模式的非法调用,javascript,angular,typescript,twitter-bootstrap,Javascript,Angular,Typescript,Twitter Bootstrap,我试图通过组件调用angular中的引导模式,而不是使用它的HTML属性。我得到一个错误(即非法调用) 组成部分: @ViewChild('myModal') div:any; ngAfterViewInit() {let bs = new bootstrap.Modal(this.div);} HTML 。。。 您需要使用该服务,而不是创建它的实例。对代码进行以下更改: import {NgbModal, ModalDismissReasons} from '@ng-bootstrap/n

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

组成部分:

@ViewChild('myModal') div:any;

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

。。。

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

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);  
}
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);  
}