Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 add injectRegisterIcons #138

Merged
merged 2 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
Loading