Skip to content

Commit 54317c1

Browse files
authored
docs(angular): clarify addIcons usage (#3222)
1 parent 3408291 commit 54317c1

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

docs/angular/build-options.md

+69
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,41 @@ export class HomePage {
113113
}
114114
```
115115

116+
Icons can also be registered in entry points such as `app.component.ts` to avoid the need to call `addIcons` multiple times. Developers should be aware that the initial application chunk may increase because the registered icons will need to be loaded at application start. However, if your application uses a small number of icons the impact of this may be minimal.
117+
118+
```typescript title="app.component.ts"
119+
import { Component } from '@angular/core';
120+
import { addIcons } from 'ionicons';
121+
import { logoIonic } from 'ionicons/icons';
122+
123+
@Component({
124+
selector: 'app-root',
125+
templateUrl: 'app.component.html',
126+
styleUrls: ['app.component.scss'],
127+
standalone: true,
128+
})
129+
export class AppComponent {
130+
constructor() {
131+
/**
132+
* Any icons you want to use in your application
133+
* can be registered in app.component.ts and then
134+
* referenced by name anywhere in your application.
135+
*/
136+
addIcons({ logoIonic });
137+
}
138+
}
139+
```
140+
141+
Icons registered in an application entry point can then be referenced by name anywhere in the application.
142+
143+
```html title="home.page.html"
144+
<!--
145+
logoIonic was registered in app.component.ts instead of home.page.ts,
146+
but it can still be used in home.page.html.
147+
-->
148+
<ion-icon name="logo-ionic"></ion-icon>
149+
```
150+
116151
**Routing**
117152

118153
Developers who wish to use `routerLink`, `routerAction`, or `routerDirection` on Ionic components should import the `IonRouterLink` directive. Developers who wish to use these routing features on anchor (`<a>`) elements should import `IonRouterLinkWithHref` instead.
@@ -218,6 +253,40 @@ export class HomePage {
218253
}
219254
```
220255

256+
Icons can also be registered in entry points such as `app.component.ts` to avoid the need to call `addIcons` multiple times. Developers should be aware that the initial application chunk may increase because the registered icons will need to be loaded at application start. However, if your application uses a small number of icons the impact of this may be minimal.
257+
258+
```typescript title="app.component.ts"
259+
import { Component } from '@angular/core';
260+
import { addIcons } from 'ionicons';
261+
import { logoIonic } from 'ionicons/icons';
262+
263+
@Component({
264+
selector: 'app-root',
265+
templateUrl: 'app.component.html',
266+
styleUrls: ['app.component.scss'],
267+
})
268+
export class AppComponent {
269+
constructor() {
270+
/**
271+
* Any icons you want to use in your application
272+
* can be registered in app.component.ts and then
273+
* referenced by name anywhere in your application.
274+
*/
275+
addIcons({ logoIonic });
276+
}
277+
}
278+
```
279+
280+
Icons registered in an application entry point can then be referenced by name anywhere in the application.
281+
282+
```html title="home.page.html"
283+
<!--
284+
logoIonic was registered in app.component.ts instead of home.page.ts,
285+
but it can still be used in home.page.html.
286+
-->
287+
<ion-icon name="logo-ionic"></ion-icon>
288+
```
289+
221290
**Routing**
222291

223292
Developers who wish to use `routerLink`, `routerAction`, or `routerDirection` on Ionic components should import the `IonRouterLink` directive. Developers who wish to use these routing features on anchor (`<a>`) elements should import `IonRouterLinkWithHref` instead.

0 commit comments

Comments
 (0)