繁体   English   中英

如何在 angular 11 的 component.ts 内的 href 中调用 function

[英]How to call function in href inside component.ts in angular 11

我有这个function过滤医院过滤医院。 然后我有一个 infoWindow 来显示信息。 单击href时,我想调用此function

filterHospitals() {
    this.hospitals = this.filterByValue(this.datasource, this.filterValue);
    this.total = this.hospitals.length;

    this.deleteMarkers();
    this.populateMapMarker();
  }

  filterByValue(items: Hospital[], filter: string) {
    return items.filter((o) =>
      Object.keys(o).some((k) => {
        if (k === 'facilityName' || k === 'facilityCategory' || k === 'clusterFacility' || k === 'stateDesc') {
          return o[k].toLowerCase().includes(filter.toLowerCase());
        }
        return null;
      })
    );
  }
marker.addListener('click', () => {
        let infoWindowContent =
          '<a href="filterHospitals()"><strong>' +
          this.camelize(this.hospitals[i].facilityName) +
          '</strong></a><br/>' +
}

单击href时如何将参数传递到function?

marker.addListener('click', () => {
    let infoWindowContent =
      '<a href="filterHospitals(facility.getAttribute(\'id\'))"
            id="'+this.hospitals[i].id+'" #facility><strong>' +
      this.camelize(this.hospitals[i].facilityName) +
      '</strong></a><br/>' +
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM