Angular Js Class Notes
Angular Js Class Notes
(20MCA23)
Faculty :
Prof.Sunita S Goravanakolla
Module 5: Angular Js(Angular Javascript)
• Introduction to Angular JS,
• Directives
• Expressions
• Controllers,
• Filters,
• Services,
• Events,
• Forms,
• Validations,
• Examples.
Module 5: Angular Js(Angular Javascript) References
• https://www.w3schools.com/angular/angular_intro.asp
• https://www.tutorialspoint.com/angularjs/index.htm#
• https://www.w3schools.com/angular/angular_ref_directives.asp
• https://www.youtube.com/watch?v=jynZZKGhFP0
• https://www.tutorialspoint.com/angularjs_online_training/index.asp
Module 5: Angular Js(Angular Javascript)
• AngularJS is a popular, open source, powerful and MVC
architecture based, frontend, JavaScript framework.
• Angular JS framework can be added to an HTML page with a
<script> tag.
• Angular JS is written in Javascript.
Note the Path for minified version of Angular JS Note the Path for uncompressed readable version
Framework (Angular JS minified file) of Angular JS Framework (Angular JS file)
Angular JS Environment setup & Linking Angular JS framework with HTML file
Module 5: Developing Angular JS Applications
https://www.youtube.com/watch?v=jynZZKGhFP0
PUT
Module 5: Developing Angular JS Applications
https://www.youtube.com/watch?v=jynZZKGhFP0
OUTPUT
Hello World Example using AngularJS.
https://www.w3schools.com/angular/tryit.asp?filename=try_ng_intro
output
One more Example on Angular JS
https://www.tutorialspoint.com/try_angularjs_on
line.php
Module 5: Angular Js(Angular JavaScript)
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.
Module 5: Angular Js(Angular JavaScript)
Steps in Creating AngularJS Application
The component
‘Model’ is
responsible for
managing the data
of the application. It
responds to the
request from the
view and it also
responds to
instructions from
the controller to
update itself.
AngularJS Directives
AngularJS directives are HTML attributes with an ng prefix.The
prefix “ng” means "Angular;" All of the built-in directives of
Angular JS use “ng” prefix.
Example: The ng-init directive initializes AngularJS application variables
Angular JS Expressions
AngularJS expressions are written inside double braces: {{ expression }}.
AngularJS will "output" data exactly where the expression is written:
Example for Angular JS is : {{ 5 + 5 }}
Example Code is as Follows:
OUTPUT
Angular JS Expressions
If you remove the ng-app directive, HTML will display the expression as
it is, without solving it:
Angular JS Expressions:ONE MORE EXAMPLE
OUTPUT
Angular JS Expressions Example expression with background colour
OUTPUT
Angular JS Directives:
• AngularJS lets you extend HTML with new attributes called Directives.
• AngularJS has a set of built-in directives which offers functionality to your applications.
• AngularJS also lets you define your own directives.
https://www.w3schools.com/angular/angular_directives.asp
AngularJS directives are extended HTML attributes with the prefix ng-.
Examples:
• The ng-app directive initializes an AngularJS application.
• The ng-model directive binds the value of HTML controls (input, select,
textarea) to application data.
Read about all AngularJS directives in AngularJS directive reference.
https://www.w3schools.com/angular/angular_ref_directives.asp
Angular JS Directives ng-init Example:
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angu
lar.min.js"></script>
<body>
<div ng-app="" ng-init="firstName='John'">
<p>Input something in the input box:</p>
<p>Name: <input type="text" ng-model="firstName"></p>
<p>You wrote: {{ firstName }}</p>
</div>
</body></html>
AngularJS ng-model Directive
The ng-model directive binds the value of HTML controls (input, select, textarea) to
application data. With the ng-model directive you can bind the value of an input
field to a variable created in AngularJS.
AngularJS ng-repeat Directive
• The ng-repeat directive in AngularJS is used to display repeating values
defined in the controller.
• Sometimes we require displaying a list of items in the view. Then the ng-
repeat directive helps us display a list of items defined in the controller using
a view section of code.
• It is like for-in in Javascript language. The JavaScript for in statement loops
through the properties of an Object.
Now,You can add controllers, directives, filters, and more, to your AngularJS
module myApp
• Adding a Controller to Module of your Angular JS application
You can Add a controller to your application, and refer to that controller with the
ng-controller directive:
OUTPUT
Why we are using "var app = angular.module('myApp', []);" ?
especially we need to know about square brackets in this line.
Answer: We are creating a module named myApp here,The first argument is the
module name myApp.
The second argument is an array of modules that this module depends on. Empty
square brackets denotes that this module does not have any dependencies on
any other modules.
https://stackoverflow.com/questions/32991765/why-we-are-using-var-app-
angular-modulemyapp-this-especially-i-nee
Angular JS Controllers Example code with initial values
Example code illustrating use of Controller by user entered values
Module 5: Angular JS 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 ng-bind directives.
• AngularJS expressions are pure JavaScript expressions and output the
data where they are used.
https://www.tutorialspoint.com/angularjs/angularjs_expressions.htm
Module 5: The following example shows the use of all the above-mentioned expressions
Module 5: Angular Js Expressions
Thank You