K
K
Konstantin2020-10-28 16:56:46
Angular
Konstantin, 2020-10-28 16:56:46

How to request a token for a class?

Banal class:

@Injectable()
export class SearchFilter {
    constructor(
        @Inject(SEARCH_CONFIG) private searchConfig: SearchConfig) {}
}


How to provide a token SEARCH_CONFIGfor a class SearchFilter in a module?

Should I use useFactory or are there other approaches?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Shvets, 2020-10-29
@Junart1

Not for the class. The token will be passed into the injector.
Injectors are created per platform, per root, per module, per directive (there is a node injector).
useFactory, useValue are already details, i.e. an indication to the injector where to get the value for this token.

P
Pavel Shvedov, 2020-10-28
@mmmaaak

Why is useClass not suitable?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question