我想我这个答案已经很晚了,但我希望它适用于有同样问题的人:问题在于:使用 angular 您可以在索引文件中执行标签,但是在组件中使用这些标签要多得多复杂,因为它上面有角度代码。所以我们要做的是避免在没有标签的情况下启动脚本。
1.在 index.html 文件(在正文中)粘贴 embed_loader:
<script type="text/javascript" src="https://ssl.gstatic.com/trends_nrtr/2578_RC02/embed_loader.js"></script>
2.现在我们转到您要显示图表的组件。创建一个包含图形的 div:
<div id="googleTrendsGraph"></div>
3.在 ngOnInit 我们保存我们创建的 HTML 组件:
const wrapper = document.getElementById('googleTrendsGraph');
4.我们将使用它的兄弟renderExploreWidgetTo而不是使用renderExploreWidget,它的作用相同,但我们指出我们放置图形的位置,这样我们就避免了使用脚本标签
ngOnInit(): void {
const wrapper = document.getElementById('googleTrendsGraph');
trends.embed.renderExploreWidgetTo(wrapper, 'TIMESERIES', {
'comparisonItem': [{
'keyword': 'cloud tourism',
'geo': 'KR',
'time': 'today 5-y'
}, {'keyword': 'computing innovations', 'geo': 'KR', 'time': 'today 5-y'}, {
'keyword': 'computing containers',
'geo': 'KR',
'time': 'today 5-y'
}, {'keyword': 'cloud services', 'geo': 'KR', 'time': 'today 5-y'}, {'keyword': 'computing ksu', 'geo': 'KR', 'time': 'today 5-y'}],
'category': 0,
'property': ''
}, {
'exploreQuery': 'date=today%205-y&geo=KR&q=cloud%20tourism,computing%20innovations,computing%20containers,cloud%20services,computing%20ksu',
'guestPath': 'https://trends.google.com:443/trends/embed/'
}); }
