Skip to content

MergeInjector breaks normal Angular DI priority #977

Description

@msgoloborodov

const mergedParentInjector = new MergeInjector(moduleInjector, parentComponentInjector);

Activity

  1. msgoloborodov commented on Jan 19, 2023

    @msgoloborodov
    ContributorAuthor

    https://angular.io/guide/hierarchical-dependency-injection#resolution-rules
    Angular tries to find dependency in ElementInjector tree, if Angular doesn't find the provider in any ElementInjector hierarchies, it goes back to the element where the request originated and looks in the ModuleInjector hierarchy.
    But UIView creates component with custom injector MergeInjector which firstly search token in ModuleInjector and then in ElementInjector.
    For example, it will return service provided in root ModuleInjector, but it must return service provided in parent component or in lazy module (child module).
    I think it should first look in all parents element injectors and only then in moduleInjector.

  2. msgoloborodov commented on Jan 23, 2023

    @msgoloborodov
    ContributorAuthor

    PR to fix this issue: #978.

  3. wawyed commented on Aug 4, 2023

    @wawyed
    Member

    When is this an issue?

  4. xfh commented on Dec 31, 2024

    @xfh

    When is this an issue?

    I haven't tested the PR yet, but I know at case where MergeInjector causes a problem. In an angular 18 app (dev-mode), lazy-loaded states are not compatible with angular devtools (chrome extension). They crash with the following error:

    ASSERTION ERROR: getInjectorParent only support injectors of type R3Injector, NodeInjector, NullInjector
        at throwError (core.mjs:525:9)
        at getInjectorParent (core.mjs:30898:5)
        at getInjectorResolutionPathHelper
    

    As a result, the angular devtools don't load. The app is working fine though. The states are loading as they should.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions