Mo Halem
Mo Halem

Reputation: 194

Angular 8 Import Service into Interface/Module

I have a service, called ConfigService in config.serivce.ts, i need to get a function (getClientID) that returns a value and import this value into a module file: appAuth.module.ts

I need to know how to inject a value from a service function in such a file?

for example in my appAuth.module.ts:

 @NgModule({
   imports: [
    CommonModule,
    AuthModule.forRoot<any>({
     adapter: getClientID(),
    })],
   providers: [],
   declarations: []
    })
   export class AppAuthModule { }

Upvotes: 0

Views: 396

Answers (1)

Joel
Joel

Reputation: 361

Wherever you need the result of getClientId() you should probably be injecting the ConfigService and call getClientId() instead of reading it from the environment.

As far as I know, your environment file shouldn't depend on anything. Instead, your Services, Components, etc. should depend on the environment file.

Here's an example from the Angular documentation on dependency injection. It shows how to inject (in this case) a UserService and a LoggerService into the UserContextService.

@Injectable({
  providedIn: 'root'
})
export class UserContextService {
  constructor(private userService: UserService, private loggerService: LoggerService) {
  }
}

See the Angular documentation for examples of how to use the environment file.

Upvotes: 2

Related Questions