I\'m trying to load some Responsive ads in an AdComponent in my app. The component is dead simple:
import { Component } from \'@angular/core\';
This is working for me:
TopBannerComponent.ts ==>
import {Component,OnInit,AfterViewInit} from '@angular/core'
@Component({
moduleId: module.id,
selector: 'google-adsense',
template: `
`,
})
export class TopBannerComponent implements AfterViewInit {
constructor() {
}
ngAfterViewInit() {
setTimeout(()=>{
try{
(window['adsbygoogle'] = window['adsbygoogle'] || []).push({});
}catch(e){
console.error("error");
}
},2000);
}
}
Add this in your html where you want your ad to appear
Add google adsense script in your main html file