Ole
Ole

Reputation: 47212

ModuleWithProviders generic type for Angular 10 Projects?

ModuleWithProviders now requires a generic type argument.

For the below module what would be the correct argument. I assume MaterialModule?

export class MaterialModule {
    constructor(public matIconRegistry: MatIconRegistry) {
         matIconRegistry.registerFontClassAlias('fontawesome', 'fa');
    }

    static forRoot(): ModuleWithProviders {
        return {
            ngModule: MaterialModule,
            providers: [MatIconRegistry]
        }
    }
}

Upvotes: 0

Views: 1386

Answers (1)

Poul Kruijt
Poul Kruijt

Reputation: 71961

You assumed right, 99.9% of the time it's the same module, at least in the forRoot method.

static forRoot(): ModuleWithProviders<MaterialModule> {
    return {
        ngModule: MaterialModule,
        providers: [MatIconRegistry]
    }
}

It's mainly used for dynamic module loader

Upvotes: 2

Related Questions