angulardependency-injection

In Angular is it possible to use Resolution Modifiers with the inject method?


Is it possible to use inject() with resolution modifiers? All examples I see point to constructor injection.

I'm trying to avoid mixing injection syntax, and the project is already using inject() all over.

I've looked all over, and I'm assuming it's not possible yet. I feel this is an oversight.


Solution

  • Yes you can pass flags to inject, see the "flags" entry under the parameters section here: https://v17.angular.io/api/core/inject

    Optional flags that control how injection is executed. The flags correspond to injection strategies that can be specified with parameter decorators @Host, @Self, @SkipSelf, and @Optional.