Categories: AndroidMobility

Cordova Hello World with AngularJS & Bootstrap

The article presents a quick code sample to get started with Cordova or PhoneGap and AngularJS and Bootstrap CSS framework.Interesting thing to note is that the development can be be same as if you are developing an AngularJS & Bootstrap Web app. This is inline with PhoneGap or Cordova being used to create a Hybrid mobile app. Following are simple steps to get started:
  • Create a HelloWorld app with Cordova or Phonegap. Take a look at our previous article on how to get started with Cordova Hello World app.
  • Once setup, what you have got is www/index.html where you could put your Bootstrap CSS path and AngularJS path.
  • As like a normal web page, create an Angular app with ng-app and ng-controller directive. Use Bootstrap “.col-xs-*” class to align UI field for smaller mobile devices.
  • Build and run. That is it.

 

Cordova/PhoneGap & AngularJS HelloWorld – Code Example

Pay attention to the angular ng directives specifying ng-app, ng-controller and ng-model. Also, notice the angular template (data binding) to display the data.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport"
 content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
<meta name="msapplication-tap-highlight" content="no" />
<title>Hello World</title>
</head>
<body>
 <div ng-app="HelloApp" ng-controller="HelloCtrl">
    <form role="form" method="post" action="#">
        <div class="form-group form-group-lg">
            <label class="col-xs-2 control-label">Name</label>
            <div class="col-xs-12">
                <input type="text" class="form-control input-lg" name="name" ng-model="name" />
            </div>
        </div>
        <div class="col-xs-10">
            <h3>Hello {{name}}!</h3>
        </div>
    </form>
 </div>
 <script type="text/javascript" src="cordova.js"></script>
 <script type="text/javascript" src="js/index.js"></script>
 <script type="text/javascript" src="js/angular.min.js"></script>
 <script type="text/javascript">
     app.initialize();
 </script>
 <script>
     var helloApp = angular.module("HelloApp", []);
     helloApp.controller("HelloCtrl", [ '$scope', function($scope) {
     $scope.name = "Calvin Hobbes";
     } ]);
 </script>
</body>
</html>

 

[adsenseyu1]

Ajitesh Kumar

I have been recently working in the area of Data analytics including Data Science and Machine Learning / Deep Learning. I am also passionate about different technologies including programming languages such as Java/JEE, Javascript, Python, R, Julia, etc, and technologies such as Blockchain, mobile computing, cloud-native technologies, application security, cloud computing platforms, big data, etc. I would love to connect with you on Linkedin. Check out my latest book titled as First Principles Thinking: Building winning products using first principles thinking.

Share
Published by
Ajitesh Kumar

Recent Posts

Creating a RAG Application Using LangGraph: Example Code

Retrieval-Augmented Generation (RAG) is an innovative generative AI method that combines retrieval-based search with large…

4 days ago

Building a RAG Application with LangChain: Example Code

The combination of Retrieval-Augmented Generation (RAG) and powerful language models enables the development of sophisticated…

5 days ago

Building an OpenAI Chatbot with LangChain

Have you ever wondered how to use OpenAI APIs to create custom chatbots? With advancements…

6 days ago

How Indexing Works in LLM-Based RAG Applications

When building a Retrieval-Augmented Generation (RAG) application powered by Large Language Models (LLMs), which combine…

1 week ago

Retrieval Augmented Generation (RAG) & LLM: Examples

Last updated: 25th Jan, 2025 Have you ever wondered how to seamlessly integrate the vast…

1 week ago

What are AI Agents? How do they work?

Artificial Intelligence (AI) agents have started becoming an integral part of our lives. Imagine asking…

4 weeks ago