SlideShare a Scribd company logo
AngularJS
JAVASCRIPT FRAMEWORK
• A JavaScript framework is a collection of JavaScript code libraries that
provide a web developer with pre-written code for routine programming
tasks. Frameworks are structures with a particular context and help you
create web applications within that context.
• It is completely possible to build strong web applications without JavaScript
frameworks, but frameworks provide a template that handles common
programming patterns. Each time you have to build an application, you
don’t need to write code for every single feature from scratch. Instead, you
can build upon an existing feature set.
• JavaScript frameworks, like most other frameworks, provide some rules
and guidelines. Using these rules and guidelines, any developer can make
complex applications faster and more efficiently than if they decided to
build from scratch. The rules and guidelines help shape and organize your
website or web application too!
• For example, think about a potter’s wheel where you can build pots.
The potter’s wheel is your framework; it has certain consistencies that
you have to work with. The wheel rotates, and you can use that
rotation to build pots of different shapes and sizes.
• You can build pots, plates, cups, bowls, or even cylindrical sculptures.
But you can’t build a house with it; you need to find a different
framework for that.
MODEL VIEW CONTROLLER (MVC)
• Modern JavaScript frameworks use a software design pattern called
Model–View–Controller. It is commonly used for developing user
interfaces that divide related programming logic into three
interconnected elements.
• The model is the central web component of the pattern as it is the
application’s dynamic data structure. It manages the data of the
application.
• The view consists of all the code that has to do with representing the
application’s data — the code for the user interface.
• The controller is the interpreter. It accepts inputs and converts them
into commands for the model or view.
• Frameworks are built around the MVC design pattern to provide
structure and adaptability in software development.
MVC Architecture
• POPULAR JAVASCRIPT FRAMEWORKS
• JavaScript is one of the most popular and widely used programming
languages globally and has more frameworks than any other
language. Since JavaScript is used for both client-side and server-side
code, there are many frameworks to work with. Some of the most
popular frameworks include:
AngularJS Introduction
• AngularJS is a JavaScript framework. It can be added to an HTML
page with a <script> tag.
• AngularJS extends HTML attributes with Directives, and binds data to
HTML with Expressions.
• AngularJS is a JavaScript framework written in JavaScript.
• AngularJS is distributed as a JavaScript file, and can be added to a
web page with a script tag:
• <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/an
gular.min.js"></script>
AngularJS Extends HTML
• AngularJS extends HTML with ng-directives.
• The ng-app directive defines an AngularJS application.
• The ng-model directive binds the value of HTML controls (input,
select, textarea) to application data.
• The ng-bind directive binds application data to the HTML view.
Creating AngularJS Application
Step 1: Load framework
Being a pure JavaScript framework, it can be added using <Script> tag.
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
Step 2: Define AngularJS application using ng-app directive
<div ng-app = ""> ...</div>
Step 3: Define a model name using ng-model directive
<p>Enter your Name: <input type = "text" ng-model = "name"></p>
Step 4: Bind the value of above model defined using ng-bind directive
<p>Hello <span ng-bind = "name"></span>!</p>
Executing AngularJS Application
Use the above-mentioned three steps in an HTML page.
• AngularJS Example
• <!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/an
gular.min.js"></script>
<body>
<div ng-app="">
<p>Name: <input type="text" ng-model="name"></p>
<p ng-bind="name"></p>
</div>
</body>
</html>
• Example explained:
• AngularJS starts automatically when the web page has loaded.
• The ng-app directive tells AngularJS that the <div> element is the
"owner" of an AngularJS application.
• The ng-model directive binds the value of the input field to the
application variable name.
• The ng-bind directive binds the content of the <p> element to the
application variable name.
• AngularJS - Directives
• AngularJS directives are used to extend HTML. They are special
attributes starting with ng-prefix. Let us discuss the following
directives −
• ng-app − This directive starts an AngularJS Application.
• ng-init − This directive initializes application data.
• ng-model − This directive defines the model that is variable to be
used in AngularJS.
• ng-repeat − This directive repeats HTML elements for each item in a
collection.
AngularJS - Expressions
Expressions are used to bind application data to HTML. Expressions are
written inside double curly braces such as in {{ expression}}. Expressions
behave similar to ngbind directives. AngularJS expressions are pure
JavaScript expressions and output the data where they are used.
Using numbers
<p>Expense on Books : {{cost * quantity}} Rs</p>
Using Strings
<p>Hello {{student.firstname + " " + student.lastname}}!</p>
Using Object
<p>Roll No: {{student.rollno}}</p>
Using Array
<p>Marks(Math): {{marks[3]}}</p>
<html>
<head>
<title>AngularJS Expressions</title>
</head>
<body>
<h1>Sample Application</h1>
<div ng-app = "" ng-init = "quantity = 1;cost = 30; student =
{firstname:'Mahesh',lastname:'Parashar',rollno:101};
marks = [80,90,75,73,60]">
<p>Hello {{student.firstname + " " + student.lastname}}!</p> <p>Expense on Books :
{{cost * quantity}} Rs</p>
<p>Roll No: {{student.rollno}}</p>
<p>Marks(Math): {{marks[3]}}</p>
</div>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</body>
</html>
• AngularJS Controllers
• AngularJS applications are controlled by controllers.
• The ng-controller directive defines the application controller.
• A controller is a JavaScript Object, created by a standard JavaScript object constructor.
• AngularJS Example
<div ng-app="myApp" ng-controller="myCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br><br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope)
{
$scope.firstName = "John";
$scope.lastName = "Doe";
});
</script>
Application explained:
The AngularJS application is defined by ng-app="myApp". The
application runs inside the <div>.
The ng-controller="myCtrl" attribute is an AngularJS directive. It
defines a controller.
The myCtrl function is a JavaScript function.
AngularJS will invoke the controller with a $scope object.
In AngularJS, $scope is the application object (the owner of application
variables and functions).
The controller creates two properties (variables) in the scope
(firstName and lastName).
The ng-model directives bind the input fields to the controller
properties (firstName and lastName).
Controller Methods
• The example above demonstrated a controller object with two properties: lastName and
firstName.
• A controller can also have methods (variables as functions):
• AngularJS Example
• <div ng-app="myApp" ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
};
});
</script>
• Controllers In External Files
• In larger applications, it is common to store controllers in external files.
• Just copy the code between the <script> tags into an external file
named personController.js:
• AngularJS Example
• <div ng-app="myApp" ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<script src="personController.js"></script>

More Related Content

Similar to AngularJS Introduction, how to run Angular (20)

PDF
One Weekend With AngularJS
Yashobanta Bai
 
PPTX
ANGULAR JS TRAINING IN PUNE
cncwebworld
 
PPTX
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
PPTX
Training On Angular Js
Mahima Radhakrishnan
 
DOCX
Angular js getting started
Hemant Mali
 
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PPTX
AngularJS is awesome
Eusebiu Schipor
 
PPTX
Angular JS training institute in Jaipur
HEMANT SAXENA
 
PPTX
Angular workshop - Full Development Guide
Nitin Giri
 
PPTX
The Basics Angular JS
OrisysIndia
 
DOCX
angularjs_tutorial.docx
telegramvip
 
PDF
AngularJS Workshop
Gianluca Cacace
 
PPTX
AngularJs Basic Concept
Hari Haran
 
PPTX
Angular tutorial
Rohit Gupta
 
PPTX
Angular Js Get Started - Complete Course
EPAM Systems
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PPTX
Introduction to Angularjs
Manish Shekhawat
 
PDF
Introduction to Angularjs : kishan kumar
Appfinz Technologies
 
One Weekend With AngularJS
Yashobanta Bai
 
ANGULAR JS TRAINING IN PUNE
cncwebworld
 
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
Training On Angular Js
Mahima Radhakrishnan
 
Angular js getting started
Hemant Mali
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
AngularJS is awesome
Eusebiu Schipor
 
Angular JS training institute in Jaipur
HEMANT SAXENA
 
Angular workshop - Full Development Guide
Nitin Giri
 
The Basics Angular JS
OrisysIndia
 
angularjs_tutorial.docx
telegramvip
 
AngularJS Workshop
Gianluca Cacace
 
AngularJs Basic Concept
Hari Haran
 
Angular tutorial
Rohit Gupta
 
Angular Js Get Started - Complete Course
EPAM Systems
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
Introduction to Angularjs
Manish Shekhawat
 
Introduction to Angularjs : kishan kumar
Appfinz Technologies
 

Recently uploaded (20)

PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PPTX
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
PDF
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
PPTX
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
PDF
Dimensions of Societal Planning in Commonism
StefanMz
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PDF
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PDF
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
PDF
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
PDF
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
PPT
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PDF
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
community health nursing question paper 2.pdf
Prince kumar
 
grade 5 lesson matatag ENGLISH 5_Q1_PPT_WEEK4.pptx
SireQuinn
 
DIGESTION OF CARBOHYDRATES,PROTEINS,LIPIDS
raviralanaresh2
 
2025 Winter SWAYAM NPTEL & A Student.pptx
Utsav Yagnik
 
Dimensions of Societal Planning in Commonism
StefanMz
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
The History of Phone Numbers in Stoke Newington by Billy Thomas
History of Stoke Newington
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
Stokey: A Jewish Village by Rachel Kolsky
History of Stoke Newington
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
QNL June Edition hosted by Pragya the official Quiz Club of the University of...
Pragya - UEM Kolkata Quiz Club
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
LAW OF CONTRACT (5 YEAR LLB & UNITARY LLB )- MODULE - 1.& 2 - LEARN THROUGH P...
APARNA T SHAIL KUMAR
 
LAW OF CONTRACT ( 5 YEAR LLB & UNITARY LLB)- MODULE-3 - LEARN THROUGH PICTURE
APARNA T SHAIL KUMAR
 
Talk on Critical Theory, Part One, Philosophy of Social Sciences
Soraj Hongladarom
 
Knee Extensor Mechanism Injuries - Orthopedic Radiologic Imaging
Sean M. Fox
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
Biological Bilingual Glossary Hindi and English Medium
World of Wisdom
 
Ad

AngularJS Introduction, how to run Angular

  • 2. JAVASCRIPT FRAMEWORK • A JavaScript framework is a collection of JavaScript code libraries that provide a web developer with pre-written code for routine programming tasks. Frameworks are structures with a particular context and help you create web applications within that context. • It is completely possible to build strong web applications without JavaScript frameworks, but frameworks provide a template that handles common programming patterns. Each time you have to build an application, you don’t need to write code for every single feature from scratch. Instead, you can build upon an existing feature set. • JavaScript frameworks, like most other frameworks, provide some rules and guidelines. Using these rules and guidelines, any developer can make complex applications faster and more efficiently than if they decided to build from scratch. The rules and guidelines help shape and organize your website or web application too!
  • 3. • For example, think about a potter’s wheel where you can build pots. The potter’s wheel is your framework; it has certain consistencies that you have to work with. The wheel rotates, and you can use that rotation to build pots of different shapes and sizes. • You can build pots, plates, cups, bowls, or even cylindrical sculptures. But you can’t build a house with it; you need to find a different framework for that.
  • 4. MODEL VIEW CONTROLLER (MVC) • Modern JavaScript frameworks use a software design pattern called Model–View–Controller. It is commonly used for developing user interfaces that divide related programming logic into three interconnected elements. • The model is the central web component of the pattern as it is the application’s dynamic data structure. It manages the data of the application. • The view consists of all the code that has to do with representing the application’s data — the code for the user interface. • The controller is the interpreter. It accepts inputs and converts them into commands for the model or view. • Frameworks are built around the MVC design pattern to provide structure and adaptability in software development.
  • 6. • POPULAR JAVASCRIPT FRAMEWORKS • JavaScript is one of the most popular and widely used programming languages globally and has more frameworks than any other language. Since JavaScript is used for both client-side and server-side code, there are many frameworks to work with. Some of the most popular frameworks include:
  • 7. AngularJS Introduction • AngularJS is a JavaScript framework. It can be added to an HTML page with a <script> tag. • AngularJS extends HTML attributes with Directives, and binds data to HTML with Expressions. • AngularJS is a JavaScript framework written in JavaScript. • AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag: • <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/an gular.min.js"></script>
  • 8. AngularJS Extends HTML • AngularJS extends HTML with ng-directives. • The ng-app directive defines an AngularJS application. • The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. • The ng-bind directive binds application data to the HTML view.
  • 9. Creating AngularJS Application Step 1: Load framework Being a pure JavaScript framework, it can be added using <Script> tag. <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> Step 2: Define AngularJS application using ng-app directive <div ng-app = ""> ...</div> Step 3: Define a model name using ng-model directive <p>Enter your Name: <input type = "text" ng-model = "name"></p> Step 4: Bind the value of above model defined using ng-bind directive <p>Hello <span ng-bind = "name"></span>!</p> Executing AngularJS Application Use the above-mentioned three steps in an HTML page.
  • 10. • AngularJS Example • <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/an gular.min.js"></script> <body> <div ng-app=""> <p>Name: <input type="text" ng-model="name"></p> <p ng-bind="name"></p> </div> </body> </html>
  • 11. • Example explained: • AngularJS starts automatically when the web page has loaded. • The ng-app directive tells AngularJS that the <div> element is the "owner" of an AngularJS application. • The ng-model directive binds the value of the input field to the application variable name. • The ng-bind directive binds the content of the <p> element to the application variable name.
  • 12. • AngularJS - Directives • AngularJS directives are used to extend HTML. They are special attributes starting with ng-prefix. Let us discuss the following directives − • ng-app − This directive starts an AngularJS Application. • ng-init − This directive initializes application data. • ng-model − This directive defines the model that is variable to be used in AngularJS. • ng-repeat − This directive repeats HTML elements for each item in a collection.
  • 13. AngularJS - Expressions Expressions are used to bind application data to HTML. Expressions are written inside double curly braces such as in {{ expression}}. Expressions behave similar to ngbind directives. AngularJS expressions are pure JavaScript expressions and output the data where they are used. Using numbers <p>Expense on Books : {{cost * quantity}} Rs</p> Using Strings <p>Hello {{student.firstname + " " + student.lastname}}!</p> Using Object <p>Roll No: {{student.rollno}}</p> Using Array <p>Marks(Math): {{marks[3]}}</p>
  • 14. <html> <head> <title>AngularJS Expressions</title> </head> <body> <h1>Sample Application</h1> <div ng-app = "" ng-init = "quantity = 1;cost = 30; student = {firstname:'Mahesh',lastname:'Parashar',rollno:101}; marks = [80,90,75,73,60]"> <p>Hello {{student.firstname + " " + student.lastname}}!</p> <p>Expense on Books : {{cost * quantity}} Rs</p> <p>Roll No: {{student.rollno}}</p> <p>Marks(Math): {{marks[3]}}</p> </div> <script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </script> </body> </html>
  • 15. • AngularJS Controllers • AngularJS applications are controlled by controllers. • The ng-controller directive defines the application controller. • A controller is a JavaScript Object, created by a standard JavaScript object constructor. • AngularJS Example <div ng-app="myApp" ng-controller="myCtrl"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br><br> Full Name: {{firstName + " " + lastName}} </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; }); </script>
  • 16. Application explained: The AngularJS application is defined by ng-app="myApp". The application runs inside the <div>. The ng-controller="myCtrl" attribute is an AngularJS directive. It defines a controller. The myCtrl function is a JavaScript function. AngularJS will invoke the controller with a $scope object. In AngularJS, $scope is the application object (the owner of application variables and functions). The controller creates two properties (variables) in the scope (firstName and lastName). The ng-model directives bind the input fields to the controller properties (firstName and lastName).
  • 17. Controller Methods • The example above demonstrated a controller object with two properties: lastName and firstName. • A controller can also have methods (variables as functions): • AngularJS Example • <div ng-app="myApp" ng-controller="personCtrl"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{fullName()}} </div> <script> var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; $scope.fullName = function() { return $scope.firstName + " " + $scope.lastName; }; }); </script>
  • 18. • Controllers In External Files • In larger applications, it is common to store controllers in external files. • Just copy the code between the <script> tags into an external file named personController.js: • AngularJS Example • <div ng-app="myApp" ng-controller="personCtrl"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{fullName()}} </div> <script src="personController.js"></script>