You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/angular/build-options.md
+98-6Lines changed: 98 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ All Ionic imports should be imported from the `@ionic/angular/standalone` submod
36
36
37
37
Ionic Angular needs to be configured when the Angular application calls `bootstrapApplication` using the `provideIonicAngular` function. Developers can pass any [IonicConfig](../developing/config#ionicconfig) values as an object in this function. Note that `provideIonicAngular` needs to be called even if no custom config is passed.
In the example below, we are importing `IonContent` and `IonButton` from `@ionic/angular/standalone` and passing them to `imports` for use in the component template. We would get a compiler error if these components were not imported and provided to the `imports` array.
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.
RouterLink, // required to get base routerLink behavior for @angular/router
133
+
IonRouterLink, // use IonRouterLinkWithHref if you are using an <a> element instead
134
+
],
135
+
})
136
+
exportclassHomePage {}
137
+
```
138
+
139
+
```html title="home.page.html"
140
+
<ion-buttonrouterLink="/foo"routerDirection="root">Go to Foo Page</ion-button>
141
+
```
142
+
116
143
### Usage with NgModule-based Applications
117
144
118
145
:::caution
@@ -123,7 +150,7 @@ All Ionic imports should be imported from the `@ionic/angular/standalone` submod
123
150
124
151
Ionic Angular needs to be configured in the `providers` array of `app.module.ts` using the `provideIonicAngular` function. Developers can pass any [IonicConfig](../developing/config#ionicconfig) values as an object in this function. Note that `provideIonicAngular` needs to be called even if no custom config is passed.
In the example below, we are importing `IonContent` and `IonButton` from `@ionic/angular/standalone` and passing them to `imports` array in the Angular component's NgModule for use in the component template. We would get a compiler error if these components were not imported and provided to the `imports` array.
@@ -168,7 +195,7 @@ We recommend calling `addIcons` in the Angular component `constructor` so the da
168
195
169
196
For developers using Ionicons 7.2 or newer, passing only the SVG data will cause the string name to be automatically generated.
170
197
171
-
```typescript
198
+
```typescript title="home.page.ts"
172
199
import { Component } from'@angular/core';
173
200
import { addIcons } from'ionicons';
174
201
import { logoIonic } from'ionicons/icons';
@@ -191,6 +218,34 @@ export class HomePage {
191
218
}
192
219
```
193
220
221
+
**Routing**
222
+
223
+
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.
RouterLink, // required to get base routerLink behavior for @angular/router
237
+
IonRouterLink, // use IonRouterLinkWithHref if you are using an <a> element instead
238
+
HomePageRoutingModule,
239
+
],
240
+
declarations: [HomePage],
241
+
})
242
+
exportclassHomePageModule {}
243
+
```
244
+
245
+
```html title="home.page.html"
246
+
<ion-buttonrouterLink="/foo"routerDirection="root">Go to Foo Page</ion-button>
247
+
```
248
+
194
249
## Modules
195
250
196
251
### Overview
@@ -332,6 +387,26 @@ export class TestComponent {
332
387
- }
333
388
```
334
389
390
+
9. If you are using `routerLink`, `routerDirection`, or `routerAction` be sure to import the `IonRouterLink` directive for Ionic components or `IonRouterLinkWithHref` directive for `<a>` elements.
391
+
392
+
```diff title="test.component.ts"
393
+
import { Component } from '@angular/core';
394
+
- import { IonButton } from '@ionic/angular/standalone';
395
+
+ import { IonButton, IonRouterLink } from '@ionic/angular/standalone';
396
+
397
+
@Component({
398
+
selector: 'app-root',
399
+
templateUrl: 'app.component.html',
400
+
styleUrls: ['app.component.scss'],
401
+
standalone: true,
402
+
imports: [
403
+
IonButton,
404
+
+ IonRouterLink
405
+
],
406
+
})
407
+
export class TestComponent {}
408
+
```
409
+
335
410
### NgModule-based Applications
336
411
337
412
Follow these steps if your Angular application is still using the NgModule architecture, but you want to adopt Ionic UI components as standalone components now.
@@ -457,3 +532,20 @@ export class TestComponentModule {}
457
532
- "output": "./svg"
458
533
- }
459
534
```
535
+
536
+
9. If you are using `routerLink`, `routerDirection`, or `routerAction` be sure to import the `IonRouterLink` directive for Ionic components or `IonRouterLinkWithHref` directive for `<a>` elements.
537
+
538
+
```diff title="test.module.ts"
539
+
import { NgModule } from '@angular/core';
540
+
import { TestComponent } from './test.component';
541
+
- import { IonButton } from '@ionic/angular/standalone';
542
+
+ import { IonButton, IonRouterLink } from '@ionic/angular/standalone';
0 commit comments