passing environment variables to angular2 library

前端 未结 5 1842
Happy的楠姐
Happy的楠姐 2020-12-08 03:04

I\'ve created company internal library using angualr2-library yeoman generator.

Some of the angular services are using environment variables in our current applicati

5条回答
  •  时光取名叫无心
    2020-12-08 03:19

    If you're trying to pass the environment variable for firebase, simply use this in your library:

    @NgModule({
      declarations: [MyAngularComponent],
      exports: [MyAngularComponent],
      imports: [
        AngularFireModule,
        AngularFirestoreModule,
        CommonModule
      ]
    })
    export class MyAngularModule {
    
      public static forRoot(firebaseConfig: FirebaseOptions): ModuleWithProviders {
    
        return {
          ngModule: MyAngularModule,
          providers: [
            { provide: FIREBASE_OPTIONS, useValue: firebaseConfig }
          ]
        }
      }
    }
    

    And import it just like AngularFire...

    MyAngularModule.forRoot(environment.firebase)
    

    From this post: pass angularFire config imported in library using forRoot

提交回复
热议问题