In the software industry, after you successfully built a web application aligned with the client requirements, you may be asked to build a mobile application for the same web application to address mobile users’ requirements. Therefore this article will provide you with better guidance to convert an existing web application developed using Angular into an Ionic native app by simple and detailed instructions.

Angular is a famous front-end web development framework which is Typescript-based and open source. Angular Components are used to modify our program HTML, CSS, and logic.

Ionic is a mobile application development framework which is an open-source SDK and guides to build HTML5 mobile applications. Ionic can handle mobile UIs in an efficient manner by bringing mobile app feeling to the user.

Let´s create a new angular project nammed “angular-ionic” , and then  navigate to that newly created directory.

ng new angular-ionic
cd angular-ionic

Our purpose is to create a mobile app for the same web application, therefore it is needed to add Ionic to the existing project. To do that you can use the Angular CLI command “ng add” to import Ionic packages to the existing project. The following command will help you to do that.

ng add @ionic/angular

After successful package installation, you will take the output as follows.

Then you must initialize your existing project with Ionic by using the following command. If you use this command you will ask a question to enter your project name. Make sure to enter the project name as your existing project name. In this case project name is angular-ionic.

ionic init

After successful initialization of Ionic to the project, you should be done below 2 changes to the angular.json file which provides details about project-specific configurations.

  1. Change outputPath “dist/angular-ionic” to “www” in the angular.json file to set folders to build Ionic project for www.

2. Change <base href=”/”> into <base href=”./”> in the index.html file. <base href=””> defines the base URL for all the relative URL is the document and by default, it is set to root.

After doing the above changes you can create an Android APK for your project and use the following command to do so.

ionic cordova run android --project="angular-ionic"

Great… You will end up with a mobile application that has been built upon your web application.

Your built Android APK can be found under the platform’s root folder and move with “platforms\android\app\build\outputs\apk\debug”. You can install it via mobile phone or by enabling the emulator you can see your Ionic mobile app!!!

It is important to notice that, you may have to fix mobile responsiveness issues of your native app like alignment issues, the appearance of icons and images, spacing issues, etc.

PS: Here you can see that with use of cordova we could render our web application into a native web view. Cordova is an open source framework which can be used to implement native application for various mobile platforms by using HTML, CSS, and JavaScript contents.

Reference:

https://levelup.gitconnected.com/

By Shabazz

Software Engineer, MCSD, Web developer & Angular specialist

Leave a Reply

Your email address will not be published. Required fields are marked *