Thanks to the easy availability of brilliant Mobile Application Development frameworks, it has become quite comfortable to come up with remarkable hybrid mobile apps that look great and function in the desired manner. Nowadays, web developers are trying their hands on combining multiple frameworks in order to arrive at an architecture that can serve as the ground base for development of fantastic mobile apps. One such combination that has been embraced by several web developers is that of PhoneGap, AngularJS and Bootstrap.
Angular 4 is out now. We can use Angular 4 to develop applications that are cross platform with maximum speed and performance. More to learn Angular 4 here.
Hybrid Mobile App Development
Today, through this post, I’ll be offering you a step wise guideline on using this perfect combination for building commendable hybrid mobile apps.
A closer look at the hybrid mobile app architecture with AngularJS, PhoneGap and Bootstrap
Talking about the architecture built using the combination of PhoneGap, AngularJS and Bootstrap, I would like to put forwards that the presentation layer is being created using the Bootstrap framework (getting started with Bootstrap Tutorial), the app logic/domain is being modeled using AngularJS (getting started with AngularJs Tutorial). This app domain/logic is being further packaged using PhoneGap/Cordova to a native mobile application.
Now, let’s have a look at the different steps associated with creation of a hybrid mobile application using a combination of AngularJS, PhoneGap and Bootstrap.
Step 1- Build an initial app template
Here, you can use the PhoneGap/Cordova CLI. All you need to do is simply execute the below command:
phonegap create appExample com.neojack.appExample AppExample
The above ‘create’ command would require the following three arguments:
- Firstly, there is a directory name which is required for generation of project. Here, it is “appExample”
- Secondly, there is a project identifier. Here, it is “com.neojack.appExample”
- Thirdly, there is a display title of the application. Here, it is “AppExample”
Step 2- Download and install Geolocation plugin
The hybrid mobile app that we are going to build in this tutorial will display current location coordinates and hence for reading these coordinated, it is necessary to install the Geolocation plugin. You can do the same by running the below command:
cordova plugin add org.apache.cordova.geolocation
Step 3- Incorporate the platform to which you want to deploy the mobile application
Here, just go to the app directory i.e. appExample and run the below command for adding iOS as the mobile platform:
phonegap platform add ios
Next, build the example app by running the below command:
phonegap build ios
Do note you can repeat this step for a mobile platform of your choice such as BlackBerry, Android, Windows Phone etc.
Step 4- Add the Bootstrap and AngularJS files to the mobile app created in the step 3
After having set the mobile platform for the app, just add the Bootstrap(bootstrap.min.css and bootstrap-theme.min.css into appExample/www/css directory) and AngularJS files(angular.min.js, angular-route.min.js etc. to appExample/www/js directory). Now, link all these files to main.html file by adding the below mentioned CSS code the head section:
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css"/>
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css"/>
<link rel="stylesheet" type="text/css" href="css/index.css" />
Code associated with linking the Javascript files is shown below:
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/angular.min.js"></script>
<script type="text/javascript" src="js/angular-route.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
Step 5- Now, code the application’s logic
You’ll require angular route config, view and an angular controller for coding the app logic. Code snippet for app.js file is shown below:
navigator.geolocation.getCurrentPosition(app.onSuccess, app.onErr);
In the above code, getCurrentPosition function requires two additional functions viz: one which is called when the current location has been obtained successfully and other one which is called when the current location of device isn’t available.
Displayed below is the success function which will be used for reading the coordinated and binding the same to the angular app i.e. appExample:
Step 6- Define the two views for the hybrid mobile application
<p class="text-center"> Your location is: <br/>
Latitude: {{latitude}}<br/>
Longitude: {{longitude}} <br/>
</p>
Step 7- Connect the coordinates to view via a controller
The structure of controller will be like this:
appExample.controller('mainController', function($scope, $route){
$scope.latitude = appExample.latitude;
$scope.longitude = appExample.longitude;
});
Step 8- Bind the controller to view via addition of router configuration
The code snippet for the router is shown below:
In the above code, router part will define a default url and ‘/about’ url. The former part would bind to main.html view while the latter one would bind to about.html view.
Step 9- Add reference for created files in index.html file
Here is how the references for last created files look like:
That’s it about developing a hybrid mobile app. Now, you must deploy it to your device for testing purpose. For this, you can either opt for a real device or a simulator.
<input id=”txtValue”/>
You need to change the HTML markup so that customers can enter only a valid three-letter country
code. Which HTML should you use?
- A. <input id=”txtValue” type=”country”/>
- B. <input id=”txtValue” type=”text” required=”xxx”/>
- C. <input id=”txtValue” type=”text” pattern-” [A-Za-z] {3} “/>
- D. <input id=”txtValuen type=”code” pattern”=”country”/>
For a complete HTML5 online test and Practice Exams, Click Here.
Correct Answer: C
Final Words
Combining AngularJS, Bootstrap and PhoneGap in the above explained manner will undoubtedly allow you to come up with stunning hybrid apps that perform excellently on multiple hand-held devices.
Author Bio
Victoria Brinsley is a mobile app programmer for Appsted Ltd – a reputed Android development company. In case, you are willing to avail a detailed information on the same, get in touch.
Top 10 Interview Questions and Answers Series:
- Top 10 HTML5 Interview Questions
- Top 10 ASP.NET MVC Interview Questions
- Top 10 ASP.NET Web API Interview Questions
- Top 10 ASP.NET Interview Questions
- Comprehensive Series of ASP.NET Interview Questions
- Top 10 ASP.NET AJAX Interview Questions
- Top 10 WCF Interview Questions
- Comprehensive Series of WCF Interview Questions