一种解决方案是通过指令阻止加载 Google 字体 //fonts.googleapis.com/css?family=Roboto
文件 google-fonts-loading-disable.directive.ts
import { Directive } from '@angular/core';
@Directive({
selector: '[appGoogleFontsLoadingDisable]'
})
export class GoogleFontsLoadingDisableDirective {
constructor() {
const head = document.getElementsByTagName('head')[0] as any;
const insertBefore = head.insertBefore;
head.insertBefore = function (newElement: any, referenceElement: any) {
if (newElement.href && newElement.href.indexOf('//fonts.googleapis.com/css?family=Roboto') > -1) {
return;
}
insertBefore.call(head, newElement, referenceElement);
};
}
}
添加在 app.modules.ts 中注册的指令
@NgModule({
declarations: [
AppComponent,
GoogleFontsLoadingDisableDirective,
并将指令与 Google 地图一起使用
<agm-map appGoogleFontsLoadingDisable [latitude]="event.geo.lat" [longitude]="event.geo.lgtd" [zoom]="14" style="height: 60vh;">
<agm-marker [latitude]="event.geo.lat" [longitude]="event.geo.lgtd" [label]="event.eventCd" [title]="event.eventCd+' '+event.eventCreatedDtm"></agm-marker>
</agm-map>