Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.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 _co.open不是函数:基于条件的运行方法_Javascript_Angular_Typescript - Fatal编程技术网

Javascript _co.open不是函数:基于条件的运行方法

Javascript _co.open不是函数:基于条件的运行方法,javascript,angular,typescript,Javascript,Angular,Typescript,我有一个方法,这个方法应该根据条件执行,在这里我打开一个模式窗口,点击地图上的标记 if(this.showMobile){ open(content) { this.modalService.open(content).result.then((result) => { this.closeResult = `Closed with: ${result}`; }, (reason) => { this.closeResult = `Dismissed ${t

我有一个方法,这个方法应该根据条件执行,在这里我打开一个模式窗口,点击地图上的标记

    if(this.showMobile){
open(content) {
  this.modalService.open(content).result.then((result) => {
  this.closeResult = `Closed with: ${result}`;
  }, (reason) => {
  this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
  });
  }
}
将open方法封装在if语句“TypeError:\u co.open不是函数”中后,会出现此错误。要根据条件打开模式窗口

<div id="dvMap"  (click)="open(content)"  style="width:900px;height:600px;"></div>

将条件放在打开的内部:

open(content) {
  if(this.showMobile) {
    this.modalService.open(content).result.then((result) => {
      this.closeResult = `Closed with: ${result}`;
    }, (reason) => {
      this.closeResult = `Dismissed ${this.getDismissReason(reason)}`;
    });
  }
}