I am using adsesne code in my angularjs application. On the first load of application ads are working fine when I switch content dynamically I get this error.
Exception in queued GPT command TypeError: Cannot read property 'addService' of null site:stackoverflow.com
.
This is the script which I load inside my div.
<script async src="https://securepubads.g.doubleclick.net/tag/js/gpt.js"></script>
<script>
window.googletag = window.googletag || {cmd: []};
googletag.cmd.push(function() {
googletag.defineSlot('/28379801/MWBanner320x50', [320, 50], 'div-adlocation').addService(googletag.pubads());
googletag.enableServices();
});
</script>
<!-- /28379801/MWBanner320x50 -->
<div id='div-adlocation' style='width: 320px; height: 50px; margin:auto'>
<script>
googletag.cmd.push(function() { googletag.display('div-adlocation'); });
</script>
</div>
Any possible work around using angularjs?