SlideShare a Scribd company logo
2
Most read
8
Most read
10
Most read
1
1. OVERVIEW
AngularJS is an open source, JavaScript based web application development
framework.
Definition of AngularJS as put by its official documentation is as follows:
AngularJS is a structural framework for dynamic web applications. It lets you use
HTML as your template language and lets you extend HTML's syntax to express your
application components clearly and succinctly. Its data binding and dependency
injection eliminate much of the code you currently have to write. And it all happens
within the browser, making it an ideal partner with any server technology.
It was originally developed in 2009 by Misko Hevery and Adam Abrons. It is now
maintained by Google.
GeneralFeatures
The most important general features of AngularJS are:
 AngularJS is a efficient framework that can create Rich Internet Applications
(RIA).
 AngularJS provides developers an options to write client side applications
using JavaScript in a clean Model View Controller (MVC) way.
 Applications written in AngularJS are cross-browser compliant. AngularJS
automatically handles JavaScript code suitable for each browser.
 AngularJS is open source, completely free, and used by thousands of
developers around the world. It is licensed under the Apache license version
2.0.
Overall, AngularJS is a framework to build large scale, high performance, and easy-
to-maintain web applications.
CoreFeatures
The most important core features of AngularJS are:
 Data-binding: It is the automatic synchronization of data between model and
view components.
 Scope: These are objects that refer to the model. They act as a glue between
controller and view.
Angular JS Tutorial
2
 Controller: These are JavaScript functions bound to a particular scope.
 Services: AngularJS comes with several built-in services such as $http to
make a XMLHttpRequests. These are singleton objects which are instantiated
only once in app.
 Filters: These select a subset of items from an array and returns a new array.
 Directives: Directives are markers on DOM elements such as elements,
attributes, css, and more. These can be used to create custom HTML tags that
serve as new, custom widgets. AngularJS has built-in directives such as
ngBind, ngModel etc.
 Templates:These are the rendered view with information from the controller
and model. These can be a single file (such as index.html) or multiple views
in one page using partials.
 Routing: It is concept of switching views.
 Model View Whatever: MVW is a design pattern for dividing an application
into different parts called Model, View, and Controller, each with distinct
responsibilities. AngularJS does not implement MVC in the traditional sense,
but rather something closer to MVVM (Model-View-ViewModel). The Angular
JS team refers it humorously as Model View Whatever.
 Deep Linking: Deep linking allows you to encode the state of application in
the URL so that it can be bookmarked. The application can then be restored
from the URL to the same state.
 Dependency Injection: AngularJS has a built-in dependency injection
subsystem that helps the developer to create,understand, and test the
applications easily.
Concepts
The following diagram depicts some important parts of AngularJS which we will
discuss in detail in the subsequent chapters.
Angular JS Tutorial
3
AdvantagesofAngularJS
The advantages of AngularJS are:
 AngularJS provides capability to create Single Page Application in a very clean
and maintainable way.
 AngularJS provides data binding capability to HTML. Thus, it gives user a rich
and responsive experience.
 AngularJS code is unit testable.
 AngularJS uses dependency injection and make use of separation of concerns.
 AngularJS provides reusable components.
 With AngularJS, the developers can achieve more functionality with short
code.
 In AngularJS, views are pure html pages, and controllers written in JavaScript
do the business processing.
Angular JS Tutorial
4
On the top of everything, AngularJS applications can run on all major browsers and
smart phones, including Android and iOS based phones/tablets.
DisadvantagesofAngulaJS
Though AngularJS comes with a lot of merits, here are some points of concern:
 Not Secure : Being JavaScript only framework, application written in
AngularJS are not safe. Server side authentication and authorization is must
to keep an application secure.
 Not degradable: If the user of your application disables JavaScript, then
nothing would be visible, except the basic page.
AngularJSDirectives
The AngularJS framework can be divided into three major parts:
 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.
5
Angular JS Tutorial
2. ENVIRONMENT
This chapter describes how to set up AngularJS library to be used in web application
development. It also briefly describes the directory structure and its contents.
When you open the link https://angularjs.org/, you will see there are two options to
download AngularJS library:
 View on GitHub- By clicking on this button, you are diverted to GitHub and
get all the latest scripts.
 Download- By clicking on this button, a screen you get to see a dialog box
shown as:
Angular JS Tutorial
6
<!doctype html>
<html>
This screen offers various options for selecting Angular JS as follows:
 Downloading and hosting files locally
o There are two different options : Legacy and Latest. The names
themselves are self descriptive. The Legacy has version less than 1.2.x
and the Latest come with version 1.3.x.
o We can also go with the minimized, uncompressed, or zipped version.
 CDN access: You also have access to a CDN. The CDN gives you access around
the world to regional data centres. In this case, the Google host. This means,
using CDN transfers the responsibility of hosting files from your own servers
to a series of external ones. This also offers an advantage that if the visitor of
your web page has already downloaded a copy of AngularJS from the same
CDN, there is no need to re-download it.
We are using the CDN versions of the library throughout this tutorial.
Example
Now let us write a simple example using AngularJS library. Let us create an HTML
filemyfirstexample.html shown as below:
Angular JS Tutorial
7
<head>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
</head>
Let us go through the above code in detail:
IncludeAngularJS
We include the AngularJS JavaScript file in the HTML page so that we can use it:
You can check the latest version of AngularJS on its official website.
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-
beta.17/angular.min.js"></script>
</head>
<body ng-app="myapp">
<div ng-controller="HelloController" >
<h2>Welcome {{helloTo.title}} to the world of Tutorialspoint!</h2>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
});
</script>
</body>
</html>
Angular JS Tutorial
8
<body ng-app="myapp">
</body>
<div ng-controller="HelloController" >
<h2>Welcome {{helloTo.title}} to the world of Tutorialspoint!</h2>
</div>
<script>
angular.module("myapp", [])
.controller("HelloController", function($scope) {
$scope.helloTo = {};
$scope.helloTo.title = "AngularJS";
});
</script>
PointtoAngularJSapp
Next, it is required to tell which part of HTML contains the AngularJS app. You can
do this by adding the ng-app attribute to the root HTML element of the AngularJS
app. You can either add it to html element or body element as shown below:
View
The view is this part:
ng-controller tells AngularJS which controller to use with this view. helloTo.title tells
AngularJS to write the model value named helloTo.title in HTML at this location.
Controller
The controller part is:
This code registers a controller function named HelloController in the angular module
named myapp. We will study more about modules and controllers in their respective
chapters. The controller function is registered in angular via the
angular.module(...).controller(...) function call.
The $scope parameter model is passed to the controller function. The controller
function adds a helloTo JavaScript object, and in that object it adds a title field.
Angular JS Tutorial
9
Execution
Save the above code as myfirstexample.html and open it in any browser. You get to
see the following output:
What happens when the page is loaded in the browser ? Let us see:
 HTML document is loaded into the browser, and evaluated by the browser.
 AngularJS JavaScript file is loaded, the angular global object is created.
 The JavaScript which registers controller functions is executed.
 Next, AngularJS scans through the HTML to search for AngularJS apps as well
as views.
 Once the view is located, it connects that view to the corresponding controller
function.
 Next, AngularJS executes the controller functions.
 It then renders the views with data from the model populated by the
controller. The page is now ready.
10
Angular JS Tutorial
Model View Controller or MVC as it is popularly called, is a software design pattern
for developing web applications. A Model View Controller pattern is made up of the
following three parts:
 Model - It is the lowest level of the pattern responsible for maintaining data.
 View - It is responsible for displaying all or a portion of the data to the user.
 Controller - It is a software Code that controls the interactions between the
Model and View.
MVC is popular as it isolates the application logic from the user interface layer and
supports separation of concerns. The controller receives all requests for the
application and then works with the model to prepare any data needed by the view.
The view then uses the data prepared by the controller to generate a final
presentable response. The MVC abstraction can be graphically represented as
follows.
3. MVC ARCHITECTURE
11
Angular JS Tutorial
Themodel
The model is responsible for managing application data. It responds to the request
from view and to the instructions from controller to update itself.
Theview
A presentation of data in a particular format, triggered by the controller's decision
to present the data. They are script-based template systems such as JSP, ASP, PHP
and very easy to integrate with AJAX technology.
Thecontroller
The controller responds to user input and performs interactions on the data model
objects. The controller receives input, validates it, and then performs business
operations that modify the state of the data model.
AngularJS is a MVC based framework. In the coming chapters, let us see how
AngularJS uses MVC methodology.
12
Angular JS Tutorial
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
<div ng-app="">
...
</div>
<p>Enter your Name: <input type="text" ng-model="name"></p>
<p>Hello <span ng-bind="name"></span>!</p>
Before creating actual Hello World ! application using AngularJS, let us see the parts
of a AngularJS application. An AngularJS application consists of following three
important parts:
 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.
CreatingAngularJSApplication
Step 1: Load framework
Being a pure JavaScript framework, it can be added using <Script> tag.
Step 2: Define AngularJS application using ng-app directive.
Step 3: Define a model name using ng-model directive.
Step 4: Bind the value of above model defined using ng-bind directive.
ExecutingAngularJSApplication
Use the above mentioned three steps in an HTML page.
4. FIRSTAPPLICATION
Angular JS Tutorial
13
<html>
<title>AngularJS First Application</title>
<body>
<h1>Sample Application</h1>
<div ng-app="">
<p>Enter your Name: <input type="text" ng-model="name"></p>
<p>Hello <span ng-bind="name"></span>!</p>
</div>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
</body>
</html>
testAngularJS.htm
Output
Open the file testAngularJS.htm in a web browser. Enter your name and see the
result.
Angular JS Tutorial
14
HowAngularJSintegrateswithHTML
 The ng-app directive indicates the start of AngularJS application.
 The ng-model directive creates a model variable named name, which can be
used with the HTML page and within the div having ng-app directive.
 The ng-bind then uses the name model to be displayed in the HTML <span>
tag whenever user enters input in the text box.
 Closing </div> tag indicates the end of AngularJS application.
15
Angular JS Tutorial
<div ng-app="">
...
</div>
<div ng-app="" ng-init="countries=[{locale:'en-US',name:'United States'},
{locale:'en-GB',name:'United Kingdom'},
{locale:'en-FR',name:'France'}]">
...
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.
ng-appdirective
The ng-app directive starts an AngularJS Application. It defines the root element. It
automatically initializes or bootstraps the application when the web page containing
AngularJS Application is loaded. It is also used to load various AngularJS modules in
AngularJS Application. In the following example, we define a default AngularJS
application using ng-app attribute of a <div> element.
ng-initdirective
The ng-init directive initializes an AngularJS Application data. It is used to assign
values to the variables. In the following example, we initialize an array of countries.
We use JSON syntax to define the array of countries.
5. DIRECTIVES
Angular JS Tutorial
16
<div ng-app="">
...
<p>Enter your Name: <input type="text" ng-model="name"></p>
</div>
<div ng-app="">
...
<p>List of Countries with locale:</p>
<ol>
<li ng-repeat="country in countries">
{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}
</li>
</ol>
</div>
<html>
<title>AngularJS Directives</title>
ng-modeldirective
The ng-model directive defines the model/variable to be used in AngularJS
Application. In the following example, we define a model named name.
ng-repeatdirective
ng-repeat directive repeats HTML elements for each item in a collection. In the
following example, we iterate over the array of countries.
Example
The following example shows the use of all the above mentioned directives.
testAngularJS.htm
</div>
Angular JS Tutorial
17
Output
Open the file testAngularJS.htm in a web browser. Enter your name and see the
result.
<body>
<h1>Sample Application</h1>
<div ng-app="" ng-init="countries=[{locale:'en-US',name:'United States'},
{locale:'en-GB',name:'United Kingdom'},
{locale:'en-FR',name:'France'}]">
<p>Enter your Name: <input type="text" ng-model="name"></p>
<p>Hello <span ng-bind="name"></span>!</p>
<p>List of Countries with locale:</p>
<ol>
<li ng-repeat="country in countries">
{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}
</li>
</ol>
</div>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js">
</script>
</body>
</html>
Angular JS Tutorial
18
Angular JS Tutorial
19

More Related Content

Similar to angularjs_tutorial.docx (20)

PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PDF
Angular js
Knoldus Inc.
 
PPTX
Ajs ppt
Avyaya Tarnaka
 
PPTX
Valentine with Angular js - Introduction
Senthil Kumar
 
PDF
angularjs-vs-angular-the-key-differences-between-javascript-and-typescript
Cuneiform Consulting Pvt Ltd.
 
PPTX
Angular Javascript Tutorial with command
ssuser42b933
 
PDF
angularjs_vs_angular_the_key_differences_between_javascript_and_typescript.pdf
sarah david
 
PDF
One Weekend With AngularJS
Yashobanta Bai
 
PPTX
ANGULAR JS TRAINING IN PUNE
cncwebworld
 
PPTX
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
PPTX
AngularJS is awesome
Eusebiu Schipor
 
PPTX
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
PPTX
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
PDF
angularjs_vs_angular_the_key_differences_between_javascript_and_typescript.pdf
sarah david
 
PPTX
Training On Angular Js
Mahima Radhakrishnan
 
PPTX
Angular JS training institute in Jaipur
HEMANT SAXENA
 
PPTX
Angular js slides
Amr Abd El Latief
 
PPTX
Angular JS Indtrodution
adesh21
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
Angular js
Knoldus Inc.
 
Valentine with Angular js - Introduction
Senthil Kumar
 
angularjs-vs-angular-the-key-differences-between-javascript-and-typescript
Cuneiform Consulting Pvt Ltd.
 
Angular Javascript Tutorial with command
ssuser42b933
 
angularjs_vs_angular_the_key_differences_between_javascript_and_typescript.pdf
sarah david
 
One Weekend With AngularJS
Yashobanta Bai
 
ANGULAR JS TRAINING IN PUNE
cncwebworld
 
Learning AngularJS - Complete coverage of AngularJS features and concepts
Suresh Patidar
 
AngularJS is awesome
Eusebiu Schipor
 
ME vs WEB - AngularJS Fundamentals
Aviran Cohen
 
AngularJS = Browser applications on steroids
Maurice De Beijer [MVP]
 
angularjs_vs_angular_the_key_differences_between_javascript_and_typescript.pdf
sarah david
 
Training On Angular Js
Mahima Radhakrishnan
 
Angular JS training institute in Jaipur
HEMANT SAXENA
 
Angular js slides
Amr Abd El Latief
 
Angular JS Indtrodution
adesh21
 

Recently uploaded (20)

PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPTX
Digital Circuits, important subject in CS
contactparinay1
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Digital Circuits, important subject in CS
contactparinay1
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
“Voice Interfaces on a Budget: Building Real-time Speech Recognition on Low-c...
Edge AI and Vision Alliance
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
Ad

angularjs_tutorial.docx

  • 1. 1 1. OVERVIEW AngularJS is an open source, JavaScript based web application development framework. Definition of AngularJS as put by its official documentation is as follows: AngularJS is a structural framework for dynamic web applications. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application components clearly and succinctly. Its data binding and dependency injection eliminate much of the code you currently have to write. And it all happens within the browser, making it an ideal partner with any server technology. It was originally developed in 2009 by Misko Hevery and Adam Abrons. It is now maintained by Google. GeneralFeatures The most important general features of AngularJS are:  AngularJS is a efficient framework that can create Rich Internet Applications (RIA).  AngularJS provides developers an options to write client side applications using JavaScript in a clean Model View Controller (MVC) way.  Applications written in AngularJS are cross-browser compliant. AngularJS automatically handles JavaScript code suitable for each browser.  AngularJS is open source, completely free, and used by thousands of developers around the world. It is licensed under the Apache license version 2.0. Overall, AngularJS is a framework to build large scale, high performance, and easy- to-maintain web applications. CoreFeatures The most important core features of AngularJS are:  Data-binding: It is the automatic synchronization of data between model and view components.  Scope: These are objects that refer to the model. They act as a glue between controller and view.
  • 2. Angular JS Tutorial 2  Controller: These are JavaScript functions bound to a particular scope.  Services: AngularJS comes with several built-in services such as $http to make a XMLHttpRequests. These are singleton objects which are instantiated only once in app.  Filters: These select a subset of items from an array and returns a new array.  Directives: Directives are markers on DOM elements such as elements, attributes, css, and more. These can be used to create custom HTML tags that serve as new, custom widgets. AngularJS has built-in directives such as ngBind, ngModel etc.  Templates:These are the rendered view with information from the controller and model. These can be a single file (such as index.html) or multiple views in one page using partials.  Routing: It is concept of switching views.  Model View Whatever: MVW is a design pattern for dividing an application into different parts called Model, View, and Controller, each with distinct responsibilities. AngularJS does not implement MVC in the traditional sense, but rather something closer to MVVM (Model-View-ViewModel). The Angular JS team refers it humorously as Model View Whatever.  Deep Linking: Deep linking allows you to encode the state of application in the URL so that it can be bookmarked. The application can then be restored from the URL to the same state.  Dependency Injection: AngularJS has a built-in dependency injection subsystem that helps the developer to create,understand, and test the applications easily. Concepts The following diagram depicts some important parts of AngularJS which we will discuss in detail in the subsequent chapters.
  • 3. Angular JS Tutorial 3 AdvantagesofAngularJS The advantages of AngularJS are:  AngularJS provides capability to create Single Page Application in a very clean and maintainable way.  AngularJS provides data binding capability to HTML. Thus, it gives user a rich and responsive experience.  AngularJS code is unit testable.  AngularJS uses dependency injection and make use of separation of concerns.  AngularJS provides reusable components.  With AngularJS, the developers can achieve more functionality with short code.  In AngularJS, views are pure html pages, and controllers written in JavaScript do the business processing.
  • 4. Angular JS Tutorial 4 On the top of everything, AngularJS applications can run on all major browsers and smart phones, including Android and iOS based phones/tablets. DisadvantagesofAngulaJS Though AngularJS comes with a lot of merits, here are some points of concern:  Not Secure : Being JavaScript only framework, application written in AngularJS are not safe. Server side authentication and authorization is must to keep an application secure.  Not degradable: If the user of your application disables JavaScript, then nothing would be visible, except the basic page. AngularJSDirectives The AngularJS framework can be divided into three major parts:  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.
  • 5. 5 Angular JS Tutorial 2. ENVIRONMENT This chapter describes how to set up AngularJS library to be used in web application development. It also briefly describes the directory structure and its contents. When you open the link https://angularjs.org/, you will see there are two options to download AngularJS library:  View on GitHub- By clicking on this button, you are diverted to GitHub and get all the latest scripts.  Download- By clicking on this button, a screen you get to see a dialog box shown as:
  • 6. Angular JS Tutorial 6 <!doctype html> <html> This screen offers various options for selecting Angular JS as follows:  Downloading and hosting files locally o There are two different options : Legacy and Latest. The names themselves are self descriptive. The Legacy has version less than 1.2.x and the Latest come with version 1.3.x. o We can also go with the minimized, uncompressed, or zipped version.  CDN access: You also have access to a CDN. The CDN gives you access around the world to regional data centres. In this case, the Google host. This means, using CDN transfers the responsibility of hosting files from your own servers to a series of external ones. This also offers an advantage that if the visitor of your web page has already downloaded a copy of AngularJS from the same CDN, there is no need to re-download it. We are using the CDN versions of the library throughout this tutorial. Example Now let us write a simple example using AngularJS library. Let us create an HTML filemyfirstexample.html shown as below:
  • 7. Angular JS Tutorial 7 <head> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> </head> Let us go through the above code in detail: IncludeAngularJS We include the AngularJS JavaScript file in the HTML page so that we can use it: You can check the latest version of AngularJS on its official website. <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0- beta.17/angular.min.js"></script> </head> <body ng-app="myapp"> <div ng-controller="HelloController" > <h2>Welcome {{helloTo.title}} to the world of Tutorialspoint!</h2> </div> <script> angular.module("myapp", []) .controller("HelloController", function($scope) { $scope.helloTo = {}; $scope.helloTo.title = "AngularJS"; }); </script> </body> </html>
  • 8. Angular JS Tutorial 8 <body ng-app="myapp"> </body> <div ng-controller="HelloController" > <h2>Welcome {{helloTo.title}} to the world of Tutorialspoint!</h2> </div> <script> angular.module("myapp", []) .controller("HelloController", function($scope) { $scope.helloTo = {}; $scope.helloTo.title = "AngularJS"; }); </script> PointtoAngularJSapp Next, it is required to tell which part of HTML contains the AngularJS app. You can do this by adding the ng-app attribute to the root HTML element of the AngularJS app. You can either add it to html element or body element as shown below: View The view is this part: ng-controller tells AngularJS which controller to use with this view. helloTo.title tells AngularJS to write the model value named helloTo.title in HTML at this location. Controller The controller part is: This code registers a controller function named HelloController in the angular module named myapp. We will study more about modules and controllers in their respective chapters. The controller function is registered in angular via the angular.module(...).controller(...) function call. The $scope parameter model is passed to the controller function. The controller function adds a helloTo JavaScript object, and in that object it adds a title field.
  • 9. Angular JS Tutorial 9 Execution Save the above code as myfirstexample.html and open it in any browser. You get to see the following output: What happens when the page is loaded in the browser ? Let us see:  HTML document is loaded into the browser, and evaluated by the browser.  AngularJS JavaScript file is loaded, the angular global object is created.  The JavaScript which registers controller functions is executed.  Next, AngularJS scans through the HTML to search for AngularJS apps as well as views.  Once the view is located, it connects that view to the corresponding controller function.  Next, AngularJS executes the controller functions.  It then renders the views with data from the model populated by the controller. The page is now ready.
  • 10. 10 Angular JS Tutorial Model View Controller or MVC as it is popularly called, is a software design pattern for developing web applications. A Model View Controller pattern is made up of the following three parts:  Model - It is the lowest level of the pattern responsible for maintaining data.  View - It is responsible for displaying all or a portion of the data to the user.  Controller - It is a software Code that controls the interactions between the Model and View. MVC is popular as it isolates the application logic from the user interface layer and supports separation of concerns. The controller receives all requests for the application and then works with the model to prepare any data needed by the view. The view then uses the data prepared by the controller to generate a final presentable response. The MVC abstraction can be graphically represented as follows. 3. MVC ARCHITECTURE
  • 11. 11 Angular JS Tutorial Themodel The model is responsible for managing application data. It responds to the request from view and to the instructions from controller to update itself. Theview A presentation of data in a particular format, triggered by the controller's decision to present the data. They are script-based template systems such as JSP, ASP, PHP and very easy to integrate with AJAX technology. Thecontroller The controller responds to user input and performs interactions on the data model objects. The controller receives input, validates it, and then performs business operations that modify the state of the data model. AngularJS is a MVC based framework. In the coming chapters, let us see how AngularJS uses MVC methodology.
  • 12. 12 Angular JS Tutorial <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> <div ng-app=""> ... </div> <p>Enter your Name: <input type="text" ng-model="name"></p> <p>Hello <span ng-bind="name"></span>!</p> Before creating actual Hello World ! application using AngularJS, let us see the parts of a AngularJS application. An AngularJS application consists of following three important parts:  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. CreatingAngularJSApplication Step 1: Load framework Being a pure JavaScript framework, it can be added using <Script> tag. Step 2: Define AngularJS application using ng-app directive. Step 3: Define a model name using ng-model directive. Step 4: Bind the value of above model defined using ng-bind directive. ExecutingAngularJSApplication Use the above mentioned three steps in an HTML page. 4. FIRSTAPPLICATION
  • 13. Angular JS Tutorial 13 <html> <title>AngularJS First Application</title> <body> <h1>Sample Application</h1> <div ng-app=""> <p>Enter your Name: <input type="text" ng-model="name"></p> <p>Hello <span ng-bind="name"></span>!</p> </div> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> </body> </html> testAngularJS.htm Output Open the file testAngularJS.htm in a web browser. Enter your name and see the result.
  • 14. Angular JS Tutorial 14 HowAngularJSintegrateswithHTML  The ng-app directive indicates the start of AngularJS application.  The ng-model directive creates a model variable named name, which can be used with the HTML page and within the div having ng-app directive.  The ng-bind then uses the name model to be displayed in the HTML <span> tag whenever user enters input in the text box.  Closing </div> tag indicates the end of AngularJS application.
  • 15. 15 Angular JS Tutorial <div ng-app=""> ... </div> <div ng-app="" ng-init="countries=[{locale:'en-US',name:'United States'}, {locale:'en-GB',name:'United Kingdom'}, {locale:'en-FR',name:'France'}]"> ... 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. ng-appdirective The ng-app directive starts an AngularJS Application. It defines the root element. It automatically initializes or bootstraps the application when the web page containing AngularJS Application is loaded. It is also used to load various AngularJS modules in AngularJS Application. In the following example, we define a default AngularJS application using ng-app attribute of a <div> element. ng-initdirective The ng-init directive initializes an AngularJS Application data. It is used to assign values to the variables. In the following example, we initialize an array of countries. We use JSON syntax to define the array of countries. 5. DIRECTIVES
  • 16. Angular JS Tutorial 16 <div ng-app=""> ... <p>Enter your Name: <input type="text" ng-model="name"></p> </div> <div ng-app=""> ... <p>List of Countries with locale:</p> <ol> <li ng-repeat="country in countries"> {{ 'Country: ' + country.name + ', Locale: ' + country.locale }} </li> </ol> </div> <html> <title>AngularJS Directives</title> ng-modeldirective The ng-model directive defines the model/variable to be used in AngularJS Application. In the following example, we define a model named name. ng-repeatdirective ng-repeat directive repeats HTML elements for each item in a collection. In the following example, we iterate over the array of countries. Example The following example shows the use of all the above mentioned directives. testAngularJS.htm </div>
  • 17. Angular JS Tutorial 17 Output Open the file testAngularJS.htm in a web browser. Enter your name and see the result. <body> <h1>Sample Application</h1> <div ng-app="" ng-init="countries=[{locale:'en-US',name:'United States'}, {locale:'en-GB',name:'United Kingdom'}, {locale:'en-FR',name:'France'}]"> <p>Enter your Name: <input type="text" ng-model="name"></p> <p>Hello <span ng-bind="name"></span>!</p> <p>List of Countries with locale:</p> <ol> <li ng-repeat="country in countries"> {{ 'Country: ' + country.name + ', Locale: ' + country.locale }} </li> </ol> </div> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"> </script> </body> </html>