javascript - Google Adsense 广告在 Angular 的所有组件上实施时不显示广告?
问题描述
我在我的网站上使用 Google Adsense,广告显示成功,但是当我想在一个组件中显示广告并在另一个组件中显示广告时,它只在一个组件中工作,并且每次它在一个组件上工作(即在左侧)
组件一
HTML
<div class="text-center">
<ins class="adsbygoogle ads_resp" style="display:inline-block" data-ad-client="publisherid" data-ad-slot="ad unit id"
data-full-width-responsive="true"></ins>
</div>
TS
声明界面 Window { adsbygoogle: any[]; }
声明 var adsbygoogle: any[];
export class OneComponent implements OnInit {
ngAfterViewInit() {
setTimeout(() => {
try {
(adsbygoogle = window["adsbygoogle"] || []).push({});
/* or
(window["adsbygoogle"] = window["adsbygoogle"] || []).push({}); Both are wrking finr*/
} catch (e) {
console.error('adsid',e);
}
}, 300);
}
}
相同的代码写在另一个组件中
并且这两个组件都包裹在另一个组件中,例如
我想将广告放在一个组件和另一个组件中,当我将广告放在两个组件中时,左侧的广告显示,右侧只有空白区域,如果我只在一个或其他组件中使用广告,那么它可以正常工作.
一件更有趣的事情,在网站的主页(左侧)上,当我放两个广告代码时,两个广告会显示,但是当同样的放在右侧时,它就不起作用了
在其他页面中,只有 1 个广告正在显示,无法显示两个广告,这两个广告仅显示在主页的左侧。
解决方案
推荐阅读
- powershell - CSV 中重复行时合并和删除 MINIMAL 结果
- z3 - 命名断言是否会影响 Z3 中检查的可满足性?
- xaml - XAML 元素标签在 Grid Canvas 上的内容对齐方式
- linux - 使子域指向特定端口
- javascript - 如何推送 mongodb 数据?
- android - view.getText().toString() 从 DialogFragment 什么都不返回?
- maven - 带有 Junit 5 的 maven 故障安全插件 - 无法使用命令行和 Junit 5 @Tag 运行过滤组
- html - Web 应用程序 - 如何使用 firebase 连接两个不同的页面?
- php - 如何在内容类型中添加新的换行符:由 php 生成的文本/纯文档?
- java - 从@controller 读取 Spring 配置文件