angular - 加载谷歌地图会破坏 css/样式表
问题描述
我有一个使用谷歌地图的简单应用程序。特别是我正在使用AgmCoreModule
和places
库:
AgmCoreModule.forRoot({
apiKey: '*********************',
libraries: ['places']
}),
除了导航到正在加载模块的页面之外,一切都工作正常,我注意到我的样式表搞砸了。像
<b>My text</b>
不要再看起来一样了。
只需导航到页面就会改变一切
对此:
看起来字体也发生了变化。
知道如何避免这种行为吗?
更新:
我注意到,当我转到加载谷歌地图的页面时,有一个对https://fonts.googleapis.com/css?family=Roboto:300,400,500,700的 GET 请求。我认为这是问题的根源。
有没有办法阻止谷歌地图这样做?
解决方案
这似乎是一个已知问题(https://github.com/SebastianM/angular-google-maps/issues/1466)。
有一种解决方法可以防止谷歌地图下载额外的字体:
<script>
var head = document.getElementsByTagName('head')[0];
// Save the original method
var insertBefore = head.insertBefore;
// Replace it!
head.insertBefore = function (newElement, referenceElement) {
if (newElement.href && newElement.href.indexOf('//fonts.googleapis.com/css?family=Roboto') > -1) {
console.info('Prevented Roboto from loading!');
return;
}
insertBefore.call(head, newElement, referenceElement);
};
</script>
推荐阅读
- delphi - How to programmatically GET and SET the Input Language by WinAPI from Delphi?
- html - fontawesome icon not appear in place holder
- python - Pipenv 始终无法锁定并产生大量错误输出
- r - connecting to clickhouse in R
- stored-procedures - Record Type in BigQuery Stored procedure
- azure-devops - trying to use set variable from predefined variables and use it in condition for stage in azure devops pipeline
- amazon-web-services - Handling load balancer
- azure-data-factory-2 - Create a ADF Dataset to load multiple csv files (same format) from the Blob
- c++ - Converting an inline-asm x87 fsqrt function from C++ to C for x86-64
- php - 解析错误?'语法错误,意外'FORMAT'(T_STRING'