Using Google Adsense ads on Angular 2 application -


i there way use google adsense ads on angular 2 app?

i've seeing google adsense ads in angular 2 components? answer isn't working me. see blank space instead of ad. i'm trying place responsive ad. did answer in above question said, template code:

<div class="text-center">     <ins class="adsbygoogle" style="display:inline-block;height:150px"     data-ad-client="my ca-pub" data-ad-slot="my ad slot"></ins>   </div> 

any ideas?

the answer in link worked me. better managed improve code can use dynamic slot info.

banner.component.ts

import { component, afterviewinit, input } "@angular/core" @component({ moduleid: module.id, selector: "google-adsense", template: ` <div>         <ins class="adsbygoogle"            style="display:block;"             data-ad-client="write_your_pub_"     [attr.data-ad-slot]="data"             data-ad-format="auto"></ins>          </div>                <br>               `,  })  export class bannercomponent implements afterviewinit { @input() data; constructor() {} ngafterviewinit() { settimeout(() => {  try {     (window["adsbygoogle"] = window["adsbygoogle"] || []).push({});   } catch (e) {     console.error(e);   } }, 2000); } } 

add in html want ad appear

<google-adsense [data]="your_slot_id"></google-adsense> 

add google adsense script in main html file

<script async src=//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js>/script> 

don't forget add app.module.

in other hand, google adsense banners doesn't show in localserver , if it's in server takes time shown up. can sure it's working changing backup ads property

fill space solid color  

in google adsense portal.


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -