第一次广告显示良好,但第二次它给出空错误。
OnInit
方法:
addGoogleAd() {
const googletag: any = window['googletag'] || {};
if (window['googletag'] && googletag.apiReady) {
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(() => {
googletag.pubads().setTargeting('site', 'weatherinnovations');
googletag.pubads().enableSingleRequest();
googletag.defineSlot('/xx/weather_innovations', [[160, 600]], 'div-gpt-ad-xx-1')
.setTargeting('position', ['s1']).addService(googletag.pubads());
googletag.defineSlot('/xx/weather_innovations', [[300, 250]], 'div-gpt-ad-xx-2')
.setTargeting('position', ['s2']).addService(googletag.pubads());
googletag.defineSlot('/xx/weather_innovations', [[300, 250]], 'div-gpt-ad-xx-3')
.setTargeting('position', ['s3']).addService(googletag.pubads());
googletag.defineSlot('/76643716/weather_innovations', [[728, 90]], 'div-gpt-ad-xx-4')
.setTargeting('position', ['s4']).addService(googletag.pubads());
googletag.defineSlot('/xx/weather_innovations', [[728, 90]], 'div-gpt-ad-xx-5')
.setTargeting('position', ['s5']).addService(googletag.pubads());
googletag.pubads().collapseEmptyDivs(true, true);
googletag.enableServices();
});
googletag.display(this.id);
}
}
仪表板加载并显示ad,但当我从另一个组件返回时,它会给出以下错误:
读取属性“setTargeting”为null
我安慰孩子们
googletag
并且不是空的,并且具有相同的内容。