SlideShare a Scribd company logo
Starting with Angular
JS
JAGRITI SRIVASTAVA
A simple html page without angularjs
<!DOCTYPE html>
<html>
<head>
<title>Angular - Demos</title>
<meta charset="utf-8" />
</head>
<body>
<div id="messageTitle"></div>
<div id="message">Hello World</div>
</body>
</html>
• In this case this html page shows
a single view .
• This is a Single Page Application,
only a portion of the page
represents the current view.
• In this case, the contents of the
body represent the view while the
HTML and HEAD elements make
up the container for the individual
views.
• To make it angular js application
there are some steps to follow.
Steps for Angular JS application
 Reference angular js framework
 Define the angular js application
 To define angular js application there are some components to be used
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
ng-app − This directive defines and links an AngularJS application to HTML.
ng-model − This directive binds the values of AngularJS application data to HTML input
controls.
ng-bind − This directive binds the AngularJS Application data to HTML tags.
 When this script loads it will examine the page and look for directives such
as the ng-view used previously.
 To bootstrap the application an ng-app directive is used, typically on the
HTML element itself.
 When AngularJS loads it will see this directive which will cause it to look for
a module named “hackApp.”
<html ng-app="hackApp">
 This single line of code defines module named “hackApp,” which will also
be used to connect controllers to the application.
 The script needs to then be referenced in the index.html page so the ng-
app directive and the module can be connected.
var hackApp = angular.module("hackApp", []);
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="scripts/ngHackApp.js"></script>
 Viewing the page in a browser results in a simple view, which shows the
heading and the static message contained in the view.
 It needs a controller and model to actually make it more than just some
HTML markup.
 The controller will be responsible for connecting the view and model and
resolves other dependencies like:
 services to consume HTTP resources.
 So the overall program with controller and view will be like this
<!DOCTYPE html>
<html ng-app="hackApp">
<head>
<title>Hack Hands Angular - Demos</title>
<meta charset="utf-8" />
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="scripts/ngHackApp.js"></script>
</head>
<body ng-controller="indexController">
<h1>Hack Hands Angular Demos</h1>
<div ng-view>
<div id="messageTitle"></div>
<div id="message">Hello World</div>
</div>
</body>
</html>
 Here ng-controller and ng-view will be working as view and controller for angularjs MVC
platform
 The ng-controller must be registered with the ANGULARJS application in order to be
resolvable by name.
 One way to register the controller is to manually add it to the JavaScript variable
representing the AngularJS application.
var indexController = hackApp.controller("indexController", function ($scope) {
// controller logic goes here
}
);
 The $scope is the dependency of the controller called the $scope object.
 The $scope parameter refers to the current scope or context for the view.
 $scope is the model used by the view.
 The model for a controller contains the data to be displayed, as well as
data to be collected in any input fields or forms.
 models may contain functions that are invoked based on user input or
other activities like clicking a button or making changes to the model data.
 The $scope object injected into the controller can be used as the model directly
 $scope can be used to declare and set a value on the model.
 AngularJS provides a rich declarative data binding experience. That means elements in
the view can have their value bound to the model.
var indexController = hackApp.controller("indexController", function
($scope) {
// controller logic goes here
$scope.message = "Hello Hacking World"
}
);
 The binding in AngularJS is two-way,
 The value can be changed by the view (e.g. changing the value in a text box) or in the model
(e.g. changing the model in a function when a button is clicked).
<div ng-view>
<div id="messageTitle"></div>
<div id="message">Hello {{message}}!</div>
<form>
<input type="text" id="name" ng-model="message" />
</form>
</div>
Using two way data binding
<form>
<input type="text" id="name" ng-model="message" />
<button ng-click="popupGreet()" value="popup">Greet</button>
</form>
var indexController = hackApp.controller("indexController", function ($scope,
$window) {
// controller logic goes here
$scope.message = "Hello Hacking World";
$scope.popupGreet = function () {
$window.alert("Hi there " + $scope.message);
};
}
);

More Related Content

DOCX
multiple views and routing
Brajesh Yadav
 
PPTX
Angular workshop
hoa long
 
PPTX
Introduction to AngularJS
David Parsons
 
PPTX
Angular js PPT
Imtiyaz Ahmad Khan
 
PPTX
Angularjs PPT
Amit Baghel
 
PDF
One Weekend With AngularJS
Yashobanta Bai
 
PPTX
Introduction to Android Programming
Raveendra R
 
PDF
AngularJS
Hiten Pratap Singh
 
multiple views and routing
Brajesh Yadav
 
Angular workshop
hoa long
 
Introduction to AngularJS
David Parsons
 
Angular js PPT
Imtiyaz Ahmad Khan
 
Angularjs PPT
Amit Baghel
 
One Weekend With AngularJS
Yashobanta Bai
 
Introduction to Android Programming
Raveendra R
 

What's hot (19)

PPTX
Angular js
ParmarAnisha
 
PDF
Angular js
Knoldus Inc.
 
PPTX
Introduction to AngularJS Framework
Raveendra R
 
DOCX
AngularJS
Ermir Hoxhaj
 
PPTX
Angular Js Get Started - Complete Course
EPAM Systems
 
PPTX
Angular js
Dinusha Nandika
 
PPTX
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
PDF
Angularjs tutorial
HarikaReddy115
 
PPTX
Training On Angular Js
Mahima Radhakrishnan
 
PPTX
Why angular js Framework
Sakthi Bro
 
PPTX
Controllers in AngularJs
K Arunkumar
 
PDF
Angular from Scratch
Christian Lilley
 
PPTX
Angular Js Basics
أحمد عبد الوهاب
 
PPTX
Angular js
sanjay joshi
 
DOCX
Different way to share data between controllers in angular js
codeandyou forums
 
PDF
Gettings started with the superheroic JavaScript library AngularJS
Armin Vieweg
 
PPTX
Understanding angular js
Aayush Shrestha
 
PPTX
Dive into Angular, part 2: Architecture
Oleksii Prohonnyi
 
Angular js
ParmarAnisha
 
Angular js
Knoldus Inc.
 
Introduction to AngularJS Framework
Raveendra R
 
AngularJS
Ermir Hoxhaj
 
Angular Js Get Started - Complete Course
EPAM Systems
 
Angular js
Dinusha Nandika
 
Dive into Angular, part 5: Experience
Oleksii Prohonnyi
 
Angularjs tutorial
HarikaReddy115
 
Training On Angular Js
Mahima Radhakrishnan
 
Why angular js Framework
Sakthi Bro
 
Controllers in AngularJs
K Arunkumar
 
Angular from Scratch
Christian Lilley
 
Angular Js Basics
أحمد عبد الوهاب
 
Angular js
sanjay joshi
 
Different way to share data between controllers in angular js
codeandyou forums
 
Gettings started with the superheroic JavaScript library AngularJS
Armin Vieweg
 
Understanding angular js
Aayush Shrestha
 
Dive into Angular, part 2: Architecture
Oleksii Prohonnyi
 
Ad

Similar to Starting with angular js (20)

PDF
Mobile phone future angular js
atanacy
 
PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PPTX
Angular js for Beginnners
Santosh Kumar Kar
 
PPTX
Angular workshop - Full Development Guide
Nitin Giri
 
PPTX
Basics of AngularJS
Filip Janevski
 
PPTX
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Jalal Mostafa
 
DOCX
ANGULAR JS LAB MANUAL(final) vtu2021 sch
kannikadg
 
PPTX
Angular js
Baldeep Sohal
 
PPTX
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
PPTX
AngularJs Basic Concept
Hari Haran
 
PDF
Introduction to AngularJS By Bharat Makwana
Bharat Makwana
 
PPT
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
PPTX
Valentine with Angular js - Introduction
Senthil Kumar
 
PDF
AngularJS Basics
Ravi Mone
 
PPTX
Intoduction to Angularjs
Gaurav Agrawal
 
PDF
Wt unit 5 client &amp; server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
PPTX
Angular Javascript Tutorial with command
ssuser42b933
 
PDF
An introduction to AngularJS
Yogesh singh
 
PPTX
ANGULARJS introduction components services and directives
SanthoshB77
 
Mobile phone future angular js
atanacy
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
Angular js for Beginnners
Santosh Kumar Kar
 
Angular workshop - Full Development Guide
Nitin Giri
 
Basics of AngularJS
Filip Janevski
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Jalal Mostafa
 
ANGULAR JS LAB MANUAL(final) vtu2021 sch
kannikadg
 
Angular js
Baldeep Sohal
 
Angular js 1.3 presentation for fed nov 2014
Sarah Hudson
 
AngularJs Basic Concept
Hari Haran
 
Introduction to AngularJS By Bharat Makwana
Bharat Makwana
 
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
Valentine with Angular js - Introduction
Senthil Kumar
 
AngularJS Basics
Ravi Mone
 
Intoduction to Angularjs
Gaurav Agrawal
 
Wt unit 5 client &amp; server side framework
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Angular Javascript Tutorial with command
ssuser42b933
 
An introduction to AngularJS
Yogesh singh
 
ANGULARJS introduction components services and directives
SanthoshB77
 
Ad

More from jagriti srivastava (15)

PDF
Map reduce with big data
jagriti srivastava
 
PPTX
Oyo rooms
jagriti srivastava
 
PPTX
Information system of amazon
jagriti srivastava
 
PPTX
JavaScript Canvas
jagriti srivastava
 
PPTX
Variable and Methods in Java
jagriti srivastava
 
PPTX
Component diagram and Deployment Diagram
jagriti srivastava
 
PPTX
Basic java, java collection Framework and Date Time API
jagriti srivastava
 
PPTX
Form validation and animation
jagriti srivastava
 
PPTX
Custom directive and scopes
jagriti srivastava
 
PPTX
Angular directive filter and routing
jagriti srivastava
 
PPTX
Angular introduction basic
jagriti srivastava
 
PPTX
Scannerclass
jagriti srivastava
 
PPTX
Programming Workshop
jagriti srivastava
 
PPTX
Java Nested class Concept
jagriti srivastava
 
PPTX
Java , A brief Introduction
jagriti srivastava
 
Map reduce with big data
jagriti srivastava
 
Information system of amazon
jagriti srivastava
 
JavaScript Canvas
jagriti srivastava
 
Variable and Methods in Java
jagriti srivastava
 
Component diagram and Deployment Diagram
jagriti srivastava
 
Basic java, java collection Framework and Date Time API
jagriti srivastava
 
Form validation and animation
jagriti srivastava
 
Custom directive and scopes
jagriti srivastava
 
Angular directive filter and routing
jagriti srivastava
 
Angular introduction basic
jagriti srivastava
 
Scannerclass
jagriti srivastava
 
Programming Workshop
jagriti srivastava
 
Java Nested class Concept
jagriti srivastava
 
Java , A brief Introduction
jagriti srivastava
 

Recently uploaded (20)

PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPT
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
PPTX
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
PPT
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
PDF
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
PDF
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Doc9.....................................
SofiaCollazos
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
Coupa-Kickoff-Meeting-Template presentai
annapureddyn
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Accelerating Oracle Database 23ai Troubleshooting with Oracle AHF Fleet Insig...
Sandesh Rao
 
What-is-the-World-Wide-Web -- Introduction
tonifi9488
 
L2 Rules of Netiquette in Empowerment technology
Archibal2
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Tea4chat - another LLM Project by Kerem Atam
a0m0rajab1
 
CIFDAQ'S Market Insight: BTC to ETH money in motion
CIFDAQ
 
Google I/O Extended 2025 Baku - all ppts
HusseinMalikMammadli
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Doc9.....................................
SofiaCollazos
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 

Starting with angular js

  • 2. A simple html page without angularjs <!DOCTYPE html> <html> <head> <title>Angular - Demos</title> <meta charset="utf-8" /> </head> <body> <div id="messageTitle"></div> <div id="message">Hello World</div> </body> </html> • In this case this html page shows a single view . • This is a Single Page Application, only a portion of the page represents the current view. • In this case, the contents of the body represent the view while the HTML and HEAD elements make up the container for the individual views. • To make it angular js application there are some steps to follow.
  • 3. Steps for Angular JS application  Reference angular js framework  Define the angular js application  To define angular js application there are some components to be used <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> ng-app − This directive defines and links an AngularJS application to HTML. ng-model − This directive binds the values of AngularJS application data to HTML input controls. ng-bind − This directive binds the AngularJS Application data to HTML tags.
  • 4.  When this script loads it will examine the page and look for directives such as the ng-view used previously.  To bootstrap the application an ng-app directive is used, typically on the HTML element itself.  When AngularJS loads it will see this directive which will cause it to look for a module named “hackApp.” <html ng-app="hackApp">
  • 5.  This single line of code defines module named “hackApp,” which will also be used to connect controllers to the application.  The script needs to then be referenced in the index.html page so the ng- app directive and the module can be connected. var hackApp = angular.module("hackApp", []); <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <script src="scripts/ngHackApp.js"></script>
  • 6.  Viewing the page in a browser results in a simple view, which shows the heading and the static message contained in the view.  It needs a controller and model to actually make it more than just some HTML markup.  The controller will be responsible for connecting the view and model and resolves other dependencies like:  services to consume HTTP resources.
  • 7.  So the overall program with controller and view will be like this <!DOCTYPE html> <html ng-app="hackApp"> <head> <title>Hack Hands Angular - Demos</title> <meta charset="utf-8" /> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <script src="scripts/ngHackApp.js"></script> </head> <body ng-controller="indexController"> <h1>Hack Hands Angular Demos</h1> <div ng-view> <div id="messageTitle"></div> <div id="message">Hello World</div> </div> </body> </html>
  • 8.  Here ng-controller and ng-view will be working as view and controller for angularjs MVC platform  The ng-controller must be registered with the ANGULARJS application in order to be resolvable by name.  One way to register the controller is to manually add it to the JavaScript variable representing the AngularJS application. var indexController = hackApp.controller("indexController", function ($scope) { // controller logic goes here } );
  • 9.  The $scope is the dependency of the controller called the $scope object.  The $scope parameter refers to the current scope or context for the view.  $scope is the model used by the view.  The model for a controller contains the data to be displayed, as well as data to be collected in any input fields or forms.  models may contain functions that are invoked based on user input or other activities like clicking a button or making changes to the model data.
  • 10.  The $scope object injected into the controller can be used as the model directly  $scope can be used to declare and set a value on the model.  AngularJS provides a rich declarative data binding experience. That means elements in the view can have their value bound to the model. var indexController = hackApp.controller("indexController", function ($scope) { // controller logic goes here $scope.message = "Hello Hacking World" } );
  • 11.  The binding in AngularJS is two-way,  The value can be changed by the view (e.g. changing the value in a text box) or in the model (e.g. changing the model in a function when a button is clicked). <div ng-view> <div id="messageTitle"></div> <div id="message">Hello {{message}}!</div> <form> <input type="text" id="name" ng-model="message" /> </form> </div>
  • 12. Using two way data binding <form> <input type="text" id="name" ng-model="message" /> <button ng-click="popupGreet()" value="popup">Greet</button> </form> var indexController = hackApp.controller("indexController", function ($scope, $window) { // controller logic goes here $scope.message = "Hello Hacking World"; $scope.popupGreet = function () { $window.alert("Hi there " + $scope.message); }; } );