问题描述: 在使用Angular 10时,ng2-adsense插件无法正确显示广告。
解决方法: 以下是一个可能的解决方法:
npm install ng2-adsense --save
import { Ng2AdsenseModule } from 'ng2-adsense';
@NgModule({
imports: [
// other imports
Ng2AdsenseModule.forRoot({
adClient: 'YOUR_AD_CLIENT',
adSlot: 'YOUR_AD_SLOT'
})
],
// other configurations
})
export class AppModule { }
注意替换YOUR_AD_CLIENT和YOUR_AD_SLOT为你自己的广告客户端ID和广告槽ID。
import { Ng2AdsenseService } from 'ng2-adsense';
@Component({
// component configurations
})
export class HomeComponent implements OnInit {
constructor(private ng2AdsenseService: Ng2AdsenseService) { }
ngOnInit() {
// call the method to show ads
this.ng2AdsenseService.pushAds();
}
}
以上是解决Angular 10中ng2-adsense插件无法正确显示广告的可能方法。请根据你的具体情况进行调整和修改。