FortAwesome / angular-fontawesome

Official Angular component for Font Awesome 5+
https://fontawesome.com
MIT License
1.49k stars 152 forks source link

Feature Request: Allow configuration to be done via EnvironmentInjectors to support use within standalone applications #399

Closed Cephyric-gh closed 1 year ago

Cephyric-gh commented 1 year ago

Describe the problem you'd like to see solved or task you'd like to see made easier

Currently the docs say that the way to set default config and/or add specific icons is to be done in the constructor of AppModule. With Angular's new standalone component system you are able to completely remove the need to use NgModule, which means that this method instead has to be done via the bootstrapped AppComponent. This config method goes against the expected functionality in Angular (config like this should be provided via the provide array of either an NgModule or the within the second argument of bootstrapAppliocation()). All the config of FaConfig, as well as the icon registration functionality in FaIconLibrary should ideally be settable via an EnvironmentInjector.

Is this in relation to an existing part of angular-fontawesome or something new?

In relation to the config settings and icon registration system.

What is 1 thing that we can do when building this feature that will guarantee that it is awesome?

Being able to provide these values via a setup similar to:

{
    providers: [
        {provide: FA_CONFIG_DEFAULTS, useValue: {defaultPrefix: 'far'},
        {provide: FA_ICONS, useValue: [faUser]},
        // and / or
        {provide: FA_ICON_PACKS, useValue: farIcons},
    ],
}

Why would other angular-fontawesome users care about this?

Standalone components are set to become the defacto usecase in Angular (in my humble opinion) as it allows for far greater tree shaking and smaller bundle sizes, so getting ahead of the curve is probably a good thing.

On a scale of 1 (sometime in the future) to 10 (absolutely right now), how soon would you recommend we make this feature?

Probably a 2-4

Feature request checklist

devoto13 commented 1 year ago

Hm, if one wishes to get rid of the AppModule, one can run the same setup code in the constructor of the AppComponent with exactly the same result. IMO it's not worth the effort to introduce the new configuration system in parallel with the existing one with subpar DX and functionality. E.g. faConfig.Cmd+Space would give list of all configuration properties while the proposed injection tokens approach would require checking documentation to get the information. The current implementation also allows users to change configuration or load icons dynamically, which isn't the case with the providers.

It also doesn't change anything in angular-fontawesome tree-shakability or lazy loading. If one wishes to make icons really lazy-loaded, then one should use explicit reference approach with deep imports for the icons.

devoto13 commented 1 year ago

Thank you for the feature request, however I don't think we're going to implement it as not feasible. I believe that the approach described in my previous comment should be sufficient to use angular-fontawesome with standalone components.