Google AdSense ads in Angular 2 components?

前端 未结 4 1175
囚心锁ツ
囚心锁ツ 2020-12-24 09:18

I\'m trying to load some Responsive ads in an AdComponent in my app. The component is dead simple:

import { Component } from \'@angular/core\';
         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-24 09:41

    There is a module that works very well for me: ng2-adsense.

    If you'll choose to use it, your HTML code will look something like this:

    
    
    

    After you install the module, you need to import it and add it to your NgModule:

    import { AdsenseModule } from 'ng2-adsense';
    @NgModule({
      declarations: [AppComponent],
      imports: [
        BrowserModule,
        AdsenseModule, // <--- Add to imports
      ],
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }
    

    And add this standard adsense code in your index.html:

    
    

提交回复
热议问题