Our Global Presence
Canada
57 Sherway St,
Stoney Creek, ON
L8J 0J3
India
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
USA
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
The migration from Ionic 3 to Ionic 4 is the most significant in the frameworks history, and it sets a course for Ionic that likely will not be deviated from for years to come.
We suggest the following general process when migrating an existing application from Ionic 3 to 4:
blank
startersrc/providers
to src/app/services
{ providedIn: 'root' }
in the @Injectable()
decorator.src/components
to src/app/components
, etc.src/app/app.scss
to src/global.scss
styleUrls
option of the @Component
decoratorIn many cases, using the Ionic CLI to generate a new object and then copying the code also works very well. For example: ionic g service weather
will create a shell Weather
service and test. The code can then be copied from the older project with minor modifications as needed. This helps to ensure proper structure is followed. This also generates shells for unit tests.
In Ionic 4, the package name is @ionic/angular
. Uninstall Ionic 3 and install Ionic 4 using the new package name:
$ npm uninstall ionic-angular $ npm install @ionic/angular
While migrating an app, update the imports from ionic-angular
to @ionic/angular
.
One of the major changes between an Ionic 3 app and an Ionic 4 app is the overall project layout and structure. In v3, Ionic apps had a custom convention for how an app should be setup and what that folder structure should look like. In v4, this has been changed to follow the recommended setup of each supported framework.
For example, if an app is using Angular, that project structure will be exactly what an Angular CLI app would be. This change, while not too difficult to accommodate, helps to keep common patterns and documentation consistent.
The above comparison is an example of a v4 app’s project structure. For developers with experience in a vanilla Angular project, this should feel really familiar.
There is a src/
directory that acts as the home for the app. This includes the index.html
, any assets, environment configuration, and any app specific config files.
While migrating an app to take advantage of this new layout, it is suggested that a new project “base” is made with the CLI. Then, with the new project layout, migrate the features of the app piece by piece. Pages/components/etc. should be moved into the src/app/
folder.
Ensure your Ionic configuration file has the appropriate type
. The project type for v3 is ionic-angular
. The project type for v4 is angular
. If this value is incorrect, the CLI may invoke the incorrect build scripts.
See the following ionic.config.json
as an example:
{ "name": "my-app", "type": "angular" }
Between V3 and V4, RxJS was updated to version 6. This changes many of the import paths of operators and core RxJS functions. Please see the RxJS Migration Guide for details.
With V4, we’re now able to utilize the typical events provided by Angular. But for certain cases, you might want to have access to the events fired when a component has finished animating during it’s route change. In this case, the ionViewWillEnter
, ionViewDidEnter
, ionViewWillLeave
, and ionViewDidLeave
have been ported over from V3. Use these events to coordinate actions with Ionic’s own animations system.
Older events like ionViewDidLoad
, ionViewCanLeave
, and ionViewCanEnter
have been removed, and the proper Angular alternatives should be used.
In prior versions of Ionic, overlay components such as Loading, Toast, or Alert were created synchronously. In Ionic v4, these components are all created asynchronously. As a result of this, the API is now promise-based.
// v3 showAlert() { const alert = this.alertCtrl.create({ message: "Hello There", subHeader: "I'm a subheader" }); alert.present(); }
In v4, promises are used:
showAlert() { this.alertCtrl.create({ message: "Hello There", subHeader: "I'm a subheader" }).then(alert => alert.present()); } // Or using async/await async showAlert() { const alert = await this.alertCtrl.create({ message: "Hello There", subHeader: "I'm a subheader" }); await alert.present(); }
Since Navigation has changed, the mechanism for lazy loading has also changed in V4.
In v3, a typical lazy loading setup worked like this:
// home.page.ts @IonicPage({ segment: 'home' }) @Component({ ... }) export class HomePage {} // home.module.ts @NgModule({ declarations: [HomePage], imports: [IonicPageModule.forChild(HomePage)] }) export class HomePageModule {}
However, in v4, lazy loading is done via the loadChildren
method of the Angular router:
// home.module.ts @NgModule({ imports: [ IonicModule, RouterModule.forChild([{ path: '', component: HomePage }]) ], declarations: [HomePage] }) export class HomePageModule {} // app.module.ts @NgModule({ declarations: [AppComponent], imports: [ BrowserModule, IonicModule.forRoot(), RouterModule.forRoot([ { path: 'home', loadChildren: './pages/home/home.module#HomePageModule' }, { path: '', redirectTo: 'home', pathMatch: 'full' } ]) ], bootstrap: [AppComponent] }) export class AppModule {}
Since v4 moved to Custom Elements, there’s been a significant change to the markup for each component. These changes have all been made to follow the Custom Elements spec, and have been documented in a dedicated file on Github.
To help with these markup changes, we’ve released a TSLint-based Migration Tool, which detects issues and can even fix some of them automatically.
For more Information and to build the app using Ionic, Hire Ionic Developer from us as we give you a high-quality product by utilizing all the latest tools and advanced technology. E-mail us any clock at – hello@hkinfosoft.com or Skype us: “hkinfosoft“.
To develop the Hybrid mobile app using Ionic, please visit our technology page.
Source:
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
57 Sherway St,
Stoney Creek, ON
L8J 0J3
606, Suvas Scala,
S P Ring Road, Nikol,
Ahmedabad 380049
1131 Baycrest Drive,
Wesley Chapel,
FL 33544
© 2024 — HK Infosoft. All Rights Reserved.
© 2024 — HK Infosoft. All Rights Reserved.
T&C | Privacy Policy | Sitemap