-
Notifications
You must be signed in to change notification settings - Fork 1
Upgrade Notes
This page contains the notes for upgrades
-
ionic serve
doesn't work for now. Useng serve
. - ionic v4 depends on angular and rxjs 6.x.
- Installed ionic cli (rc)
npm i -g ionic@rc
- Created a new project
ionic start v4-ion-meetups tabs --type=angular
The following steps copy listed directories from v3 project to listed destinations in v4 project.
- Copied
/src/pages
to/src/app/pages
- Copied
/src/models
to/src/app/models
- Copied
/src/providers
to/src/app/providers
. - Copied
/src/utils
to/src/app/utils
.
Now getting error Can't resolve module ionic-angular
. Fixing this.
-
Breaking From all the individual pages' modules, replaced
IonicPageModule
andIonicPageModule.forRoot...
withIonicModule
. -
Replaced
ionic-angular
with@ionic/angular
. -
Breaking
NavController
andNavParams
aren't compatible with angular routing in v4. Use angular'sRouter
andActivatedRoute
for similar use. -
Breaking There's no
ViewController
in v4. If you're using it for modals, replace it withModalController
from@ionic/angular
. -
Breaking
ActionSheetController#create
now returns a promise for the action sheet, instead of action sheet itself. -
Breaking Major
ionViewDidLoad
lifecycle callback doesn't work in v4. Since it's just angular routing, usengOnInit
.
Upgrading routes:
- Getting the container tabs page to work first
-
Breaking Added a routes definition with only Tabs page, and blank redirect routes to start with. Also imported the routes in
TabsPageModule
.
const routes: Routes = [
{
path: 'tabs',
component: TabsPage
},
{
path: '',
redirectTo: '/tabs',
pathMatch: 'full'
}
];
Getting error that root is not a known property of ion-tab
. Expected since ion-tab
has a different API/usage in v4.
-
Breaking Renamed
tabIcon
toicon
forion-tab
element. -
Breaking Replaced
[root]...
withhref=
attribute. -
Breaking Renamed
tabTitle
tolabel
. -
Breaking
ion-tab
also needs a child elemention-router-outlet
. This new element takes aname
attribute which helps in specifying which components go in which tab while writing routes.
This gets the tab page working, but obviously shows blank tab content.
Getting about page loading
-
In
about.module.ts
, added entry component withAboutPage
component. Also, added aRouterModule.forChild
import to the module with blank path,AboutPage
component andabout
outlet. This outlet tells this route which router outlet to target when loading. Since we're lazy loading, we need to specify this outlet in both - tabs module and about page module. -
In
tabs.module.ts
, add a new child route for maintabs
route:
{
path: 'tabs',
component: TabsPage,
children: [
{
path: 'about',
outlet: 'about',
loadChildren: '../about/about.module#AboutPageModule'
}
]
}
This allows lazy loading AboutPage
component into ion-router-outlet
with the name about
inside tabs.html
.
I've observed it would have been better if I brought over one page at a time into this project. Even though I'm really only working to get one page running at a time, all pages throw upgrade related error which have to be fixed/commented to get them out of the way until I can get to their pages.
Getting Users list and details page loading
- Follow instructions for
About
page from above, except forusers.module.ts
in this case. -
Breaking
ion-navbar
isn't present in v4. Replace it withion-toolbar
. Also, if we need back button, we need to add it manually (ion-navbar took care of that in v3). Throw the following code inside theion-toolbar
for a button:
<ion-buttons slot="start">
<ion-back-button text="Users" defaultHref="/tabs/(users:user-list)"></ion-back-button>
</ion-buttons>
-
Breaking
[item-start]
and[item-end]
attributes aren't available on ionic elements in v4.Replace it withslot="start"
andslot="end"
respectively instead. - Breaking We need to replace code for navigation to another page (user detail). Replace
this.navCtrl.goForward('users-detail-page', {user});
with
this.router.navigateByUrl(`tabs/(users:user-detail/${user.email})`);
- Add import for
RouterModule.forChild
inuser-detail.module.ts
. - Add new route with parameters to
tabs.module.ts
. Looks like this:
{
name: 'user-detail/:email,
outlet: 'users',
loadChildren: '../user-detail/user-detail.module#UserDetailPageModule'
}
-
Breaking In
user-detail.ts
, we need to update how we're reading parameter. We can't usenavParams.get
anymore, since we're using angular's native routing. InjectActivatedRoute
dependency in component, and usethis.route.snapshot.paramMap.get('email')
for this.
Note: Breaking With v3 ionic router, it was possible to send entire objects as route parameters. That's not an option since parameters are reflected in url. So either A. the code needs to be updated to communicate via primitive params or B. use service for communication. Update v3 app to use primitive params in routes before beginning upgrade
Getting events page, dialog and event-details page loading
- Configure the routes etc. similar to previous pages.
-
Breaking In action sheet's parameter,
title
property is renamed toheader
. -
<ion-fab right bottom>
becomes<ion-fab vertical="bottom" horizonal="end">
. - The
<button>
insideion-fab
is replaced by<ion-fab-button>
. -
<ion-fab>
now lies outside<ion-content>
. - If you have
<button ion-button>
elements inside<ion-buttons>
, replace them with<ion-button>
.
Since we're not using Angular, the way ionic pages had an element in v3, which you could access in the style file is no longer the case. So previously we had:
page-about {
.about-page {
&__contributors {
.details {
margin-left: 10px;
}
}
}
}
Where ionic used to have this page-about
selector already put in the stylesheet. Now, you can either get rid of this parent selector, or if you had styles to this root page selector, you can use :host
instead. I.e.
:host {
.about-page {
&__contributors {
.details {
margin-left: 10px;
}
}
}
}