Skip to content

DynamicComponentLoader.loadNextToLocation and injector #5990

@vincentdieltiens

Description

@vincentdieltiens

Hi,

Why should we pass a ResolvedProvider[]to DynamicComponentLoader.loadNextToLocation instead of an Injector ?

I'm writing a small dialog system and I have a DialogService.open method which uses DynamicComponentLoader.loadNextToLocation to load a component inside the dialog. All is working fine until the loaded component asks for providers.

I can add a providers parameters to the DialogService.open method but it means that the user have to explicitly make something like this :

@Component({
    selector: 'my-app',
    providers: [DialogService]
})
class AppComponent {
    constructor(dialogService:DialogService) {
        var providers = Injector.resolve([
            FakeService
        ]);
        dialogService.open(MyDialogContentComponent, providers);
    }
}

I would like to let the dialogService use the injector of the AppComponent and let the possibility to do something like this :

@Component({
    selector: 'my-app',
    providers: [DialogService, FakeService]
})
class AppComponent {
    constructor(dialogService:DialogService) {
        dialogService.open(MyDialogContentComponent);
    }
}

What's the best way to do this ?

Thanks

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