0

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 { }

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I need to know how to inject the service in such a file?
@MoHalem: I updated the answer with an example and a link to the dependency injection guide.
Yes i know this way is but this is for injecting into a class, what if i want to inject into an interface or a module?
Could you give an example of what you are trying to achieve? An Interface has no need (and can't) inject anything, it only declares how something else (that implements it) can be used.
What is getClientID? Is it something that is global for the whole application? Where is the AuthModule coming from? How is it solved it in their documentation?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.