@@ -102,12 +102,14 @@ During setup phase you can provide additional optional settings such as:
102102 svgLoadStrategy ?: Type < SvgLoadStrategy > ;
103103```
104104
105- ` svgLoadStrategy ` can be any injectable class that has ` load ` method that accepts url and returns observable string:
105+ ` svgLoadStrategy ` can be any injectable class that has ` config ` that excepts method that accepts url and returns observable string,
106+ and ` load ` which accepts the configured url as an observable and returns the svg as an observable string.
106107
107108``` typescript
108109@Injectable ()
109110export abstract class SvgLoadStrategy {
110- abstract load(url : string ): Observable <string >;
111+ abstract config(url : string ): Observable <string >;
112+ abstract load(url : Observable <string >): Observable <string >;
111113}
112114```
113115
@@ -164,10 +166,9 @@ You can provide your own SSR loading strategy that can look like this:
164166``` typescript
165167@Injectable ()
166168export class SvgLoadStrategySsr implements SvgLoadStrategy {
167- load(url : string ): Observable <string > {
168- const iconPath = join (process .cwd (), ' dist' , ' app-name' , ' browser' , url );
169- const iconSVG = readFileSync (iconPath , ' utf8' );
170- return of (iconSVG );
169+ config = (url : string ) => of (join (cwd (), ' path' , ' to' , ' svg' , ' assets' , url ));
170+ load(iconPath$ : Observable <string >) {
171+ return iconPath$ .pipe (switchMap ((iconPath ) => from (readFile (iconPath , { encoding: ' utf8' }))));
171172 }
172173}
173174```
@@ -187,14 +188,44 @@ And then just provide it in you server module.
187188 providers: [
188189 provideFastSVG ({
189190 svgLoadStrategy: SvgLoadStrategySsr ,
190- url : (name : string ) => ` assets/svg-icons/ ${name }.svg` ,
191+ url : (name : string ) => ` ${name }.svg ` ,
191192 }),
192193 ],
193194 bootstrap: [AppComponent ],
194195})
195196export class AppServerModule {}
196197```
197198
199+ #### Providing a lazy configuration
200+
201+ If you need to provide a lazy configuration you can use the config method in the ` SvgLoadStrategy ` :
202+
203+ ``` typescript
204+ @Injectable ()
205+ class LazyConfigSvgLoadStrategy extends SvgLoadStrategyImpl {
206+ lazyConfigService = inject (SvgConfigService );
207+ override config(url : string ) {
208+ return this .lazyConfigService .urlConfig (url );
209+ }
210+ }
211+ ```
212+
213+ And pass it to the provider function:
214+
215+ ``` typescript
216+ import { provideFastSVG } from ' @push-based/ngx-fast-svg' ;
217+
218+ bootstrapApplication (AppComponent , {
219+ providers: [
220+ // ... other providers
221+ provideFastSVG ({
222+ url : (name : string ): Observable <string > => inject (ConfigService ).svgUrl (name ),
223+ svgLoadStrategy: LazyConfigSvgLoadStrategy ,
224+ })
225+ ]
226+ });
227+ ```
228+
198229## Features
199230
200231### :sloth : Lazy loading for SVGs
0 commit comments