Skip to content

Commit

Permalink
feat: 🎸 add injectRegisterIcons (#138)
Browse files Browse the repository at this point in the history
* feat: 🎸 add injectRegisterIcons

* docs: ✏️ update readme
  • Loading branch information
shaharkazaz committed Jul 24, 2023
1 parent f4d26b0 commit 749768b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,28 @@ export class AppComponent {
}
```

You can also use the `injectRegisterIcons` method to register icons using the new `inject` API:

```ts
import { injectRegisterIcons } from '@ngneat/svg-icon';

interface Icon {
name: string;
data: string;
}

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
constructor() {
injectRegisterIcons([Icon, Icon, Icon]);
}
}
```

## Missing Icon

You can define **missingIconFallback** which will be used if icon is not found in registry:
Expand Down
8 changes: 8 additions & 0 deletions projects/ngneat/svg-icon/src/lib/injection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {inject} from "@angular/core";
import {SvgIconRegistry} from "@ngneat/svg-icon";

export function injectRegisterIcons(
...params: Parameters<(typeof SvgIconRegistry.prototype)['register']>
) {
inject(SvgIconRegistry).register(...params);
}
1 change: 1 addition & 0 deletions projects/ngneat/svg-icon/src/public-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export { SvgIconRegistry } from './lib/registry';
export { provideSvgIcons, provideSvgIconsConfig } from './lib/providers';
export { SvgIcons } from './lib/types';
export { SvgToDataUrlPipe } from './lib/data-url.pipe';
export { injectRegisterIcons } from './lib/injection';

0 comments on commit 749768b

Please sign in to comment.