scttcper / ng2-adsense

Angular Adsense Component
https://ng2-adsense.xmplaylist.com
MIT License
138 stars 24 forks source link

Allow usage without forRoot #372

Open naveedahmed1 opened 5 years ago

naveedahmed1 commented 5 years ago

The current docs states that we should add AdsenseModule.forRoot to the app module, as a result, this plugin becomes part of the main bundle.

What if we are using it in just 1-2 sections of the website and don't want it to be a part of main bundle. Currently we still have to add it to app module.

It would be great to allow usage without adding it to app module and without forRoot.

Can this use case be supported?

scttcper commented 5 years ago

I think you could. Might need to make a provider for the injection token? https://github.com/scttcper/ng2-adsense/blob/master/src/lib/adsense.component.ts#L67

naveedahmed1 commented 5 years ago

Can you please provide some more details about how to do this?

Ideki commented 4 years ago

You could also use a shared module

import { NgModule } from '@angular/core';

import { AdsenseModule } from 'ng2-adsense';

@NgModule({
  declarations: [
  ],
  imports: [
    AdsenseModule.forRoot({
      adClient: 'yourNumberHere'
    })
  ],
  exports: [
    AdsenseModule
  ]
})
export class SharedModule { }