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
This migration guide assumes the Angular components in your application are already standalone components. See [Migrating to Standalone](https://angular.io/guide/standalone-migration) if your Angular application is not already using standalone components.
155
-
:::
153
+
The Standalone option is newer than the Modules option, so developers may wish to switch during the development of their application. This guide details the steps needed to migrate.
154
+
155
+
Note that migrating to Ionic standalone components must be done all at the same time and cannot be done gradually. The Modules and Standalone approaches use two different build systems of Ionic that cannot be used at the same time.
156
156
157
-
The Standalone option is newer than the Modules option, so developers may wish to switch during the development of their application. This guide details the steps needed to migrate as well as limitations to be aware of.
157
+
### Using Ionic Standalone Components in Standalone-based Applications
158
158
159
-
### Steps to Migrate
159
+
Follow these steps if your Angular application is already using the standalone architecture, and you want to use Ionic UI components as standalone components too.
160
160
161
161
1. Run `npm install @ionic/angular@latest` to ensure you are running the latest version of Ionic. Ionic UI Standalone Components is supported in Ionic v7.5 or newer.
162
162
163
163
2. Run `npm install ionicons@latest` to ensure you are running the latest version of Ionicons. Ionicons v7.2 brings usability improvements that reduce the code boilerplate needed to use icons with standalone components.
164
164
165
165
3. Remove the `IonicModule` call in `main.ts` in favor of `provideIonicAngular` imported from `@ionic/angular/standalone`. Any config passed to `IonicModule.forRoot` can be passed as an object to this new function.
166
166
167
-
```diff
167
+
```diff title="main.ts"
168
168
import { enableProdMode, importProvidersFrom } from '@angular/core';
169
169
import { bootstrapApplication } from '@angular/platform-browser';
170
170
import { RouteReuseStrategy, provideRouter } from '@angular/router';
6. Add imports for each Ionic component in the Angular component where they are used. Be sure to pass the imports to the `imports` array on your Angular component.
202
202
203
-
```diff
203
+
```diff title="app.component.ts"
204
204
import { Component } from '@angular/core';
205
205
+ import { IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
206
206
@@ -218,7 +218,7 @@ export class AppComponent {
218
218
219
219
7. If you are using Ionicons, define the icon SVG data used in each Angular component using `addIcons`. This allows you to continue referencing icons by string name in your component template. Note that you will need to do this for any additional icons added.
220
220
221
-
```diff
221
+
```diff title="test.component.ts"
222
222
import { Component } from '@angular/core';
223
223
+ import { IonIcon } from '@ionic/angular/standalone';
224
224
+ import { addIcons } from 'ionicons';
@@ -233,22 +233,137 @@ import { Component } from '@angular/core';
233
233
})
234
234
export class TestComponent {
235
235
constructor() {
236
-
addIcons({ alarm, logoIonic });
236
+
+ addIcons({ alarm, logoIonic });
237
237
}
238
238
}
239
239
```
240
240
241
241
8. Remove the following code from your `angular.json` file if present. Note that it may appear multiple times.
### Using Ionic Standalone Components in NgModule-based Applications
252
+
253
+
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.
254
+
255
+
1. Run `npm install @ionic/angular@latest` to ensure you are running the latest version of Ionic. Ionic UI Standalone Components is supported in Ionic v7.5 or newer.
256
+
257
+
2. Run `npm install ionicons@latest` to ensure you are running the latest version of Ionicons. Ionicons v7.2 brings usability improvements that reduce the code boilerplate needed to use icons with standalone components.
258
+
259
+
3. Remove the `IonicModule` call in `app.module.ts` in favor of `provideIonicAngular` imported from `@ionic/angular/standalone`. Any config passed to `IonicModule.forRoot` can be passed as an object to this new function.
260
+
261
+
```diff title="app.module.ts"
262
+
import { enableProdMode, importProvidersFrom } from '@angular/core';
263
+
import { bootstrapApplication } from '@angular/platform-browser';
264
+
import { RouteReuseStrategy, provideRouter } from '@angular/router';
265
+
- import { IonicModule, IonicRouteStrategy } from '@ionic/angular';
266
+
+ import { provideIonicAngular, IonicRouteStrategy } from '@ionic/angular/standalone';
267
+
268
+
import { routes } from './app/app.routes';
269
+
import { AppComponent } from './app/app.component';
270
+
import { environment } from './environments/environment';
4. Remove any references to `IonicModule` found elsewhere in your application.
290
+
291
+
5. Update any existing imports from `@ionic/angular` to import from `@ionic/angular/standalone` instead.
292
+
293
+
```diff
294
+
- import { Platform } from '@ionic/angular';
295
+
+ import { Platform } from '@ionic/angular/standalone';
296
+
```
297
+
298
+
6. Add imports for each Ionic component in the NgModule for the Angular component where they are used. Be sure to pass the components to the `imports` array on the module.
299
+
300
+
```diff title="app.module.ts"
301
+
import { enableProdMode, importProvidersFrom } from '@angular/core';
302
+
import { bootstrapApplication } from '@angular/platform-browser';
303
+
import { RouteReuseStrategy, provideRouter } from '@angular/router';
304
+
- import { provideIonicAngular, IonicRouteStrategy } from '@ionic/angular/standalone';
305
+
+ import { provideIonicAngular, IonicRouteStrategy, IonApp, IonRouterOutlet } from '@ionic/angular/standalone';
306
+
307
+
import { routes } from './app/app.routes';
308
+
import { AppComponent } from './app/app.component';
309
+
import { environment } from './environments/environment';
7. If you are using Ionicons, define the icon SVG data used in each Angular component using `addIcons`. This allows you to continue referencing icons by string name in your component template. Note that you will need to do this for any additional icons added. The `IonIcon` component should still be provided in the NgModule.
329
+
330
+
```diff title="test.component.ts"
331
+
import { Component } from '@angular/core';
332
+
+ import { addIcons } from 'ionicons';
333
+
+ import { alarm, logoIonic } from 'ionicons/icons';
334
+
335
+
@Component({
336
+
selector: 'app-root',
337
+
templateUrl: 'app.component.html',
338
+
styleUrls: ['app.component.scss'],
339
+
})
340
+
export class TestComponent {
341
+
constructor() {
342
+
addIcons({ alarm, logoIonic });
343
+
}
344
+
}
345
+
```
346
+
347
+
```diff title="test.module.ts"
348
+
import { NgModule } from '@angular/core';
349
+
import { TestComponent } from './test.component';
350
+
+ import { IonIcon } from '@ionic/angular/standalone';
252
351
253
-
1. Your application must already make use of standalone APIs. Using Ionic UI components as standalone components in an application that uses `NgModule` is not supported.
254
-
2. Migrating to Ionic standalone components must be done all at the same time and cannot be done gradually. The Modules and Standalone approaches use two different build systems of Ionic that cannot be used at the same time.
352
+
@NgModule({
353
+
imports: [
354
+
+ IonIcon,
355
+
],
356
+
declarations: [TestComponent]
357
+
})
358
+
export class TestComponentModule {}
359
+
```
360
+
361
+
8. Remove the following code from your `angular.json` file if present. Note that it may appear multiple times.
0 commit comments