SlideShare a Scribd company logo
1 of 23
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
What is AngularJS
AngularJS is an open source JavaScript framework to develop web based
applications. AngularJS is having two versions i.e. AngularJS 1 and
AngularJS 2.
Advantage of AngularJS
 Easy to Code
 Best framework to create SPA(Single Page Application)
 It supports MVC(Model View Controller) concept
 It supports routing
 It provides dependency injection
1
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
How to Set AngularJS environment
As we know AngularJS is JavaScript framework so first we need to add
javascript file which AngularJS is using. It is using angular.js file to work.
Go to the angularJS official website to download angular.js file
https://angularjs.org/
How to Add angular.js in View
We need to add the Script tag in HTML file (Any UI which you are using) in which we
add source of angular.js file.
<script src="angular.min.js"></script>
2
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
Directives
Directives in angularJS extends HTML code to provide new behaviour.
In angularJS we use ng keyword which means angular. All directives in angularJS starts from ng.
3
Types of
Directives
Built-in
Custom
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
Ng-app Directives
ng-app directive is the beginning directive of angularJS. It is used to auto bootstrap angularJS
application. We generally use this directive at root level like inside html tag or in body tag.
When angularJS application loads it will first search for ng-app directives.
In other words, you can say that it is used to inform angularJS framework from where it has to
initiate.
Syntax of ng-app
Add ng-app tag in body tag in the following manner:-
<body data-ng-app>
</body>
4
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
Binding Expression
In angularJS we use {{ }} for binding expression. For any kind of evaluation, we can
perform inside this binding expression
Example of ng-app
<body ng-app>
<p>The sum of 20 and 30 is </p>
<p>{{20+30}}</p>
</body>
In this example it will simply evaluate the sum and display.
Note :- We use data-ng-app directives to validate HTML5. it will consider data-ng-app as custom
attribute.
5
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
Module in AngularJS
Module in angularjs is just like container which is having the business logics,
controllers, services etc.
How to declare Module
To create module, we use angular.module function. In this function we pass first parameter as module
name and second parameter is dependent module. If do not have any dependent module then we can
leave it as blank.
var angmodule= angular.module('mymodule',[ ])
in this code mymodule is module name and empty array represents that there is no dependency on
module.
We can use this module with ng-app in the following manner
ng-app="mymodule"
6
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
MVC Architecture
MVC Stands for Model View Controller. In MVC view represents the user interface and model is the
data. Both view and model is independent to each other. Controller is like bridge between model and
view.
What is Controller
In angularJS controller is JavaScript function object. We need to create controller inside module. We use
ng-controller directive to add controller.
7
What is $scope
$scope is the kind of object which represents the application model. It is used to pass data between
view and controller. We can add properties and function in this scope and we can use it in View.
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Example of MVC
In this example we are creating a controller in which we need to pass data to view i.e. the name of the
course along with the fees. So we will write the code in the following manner
8
<!DOCTYPE html>
<html>
<head>
<script src="angular.min.js"></script>
<script>
var angmodule=
angular.module('mymodule',[]).controller('course',
function($scope){ $scope.coursename='Asp.net';
$scope.fees='15000';
});
</script>
</head>
<body ng-app="mymodule">
<div ng-controller="course">
<p>Course: {{ coursename }}</p>
<p>Fees: {{ fees }}</p>
</div>
</body>
</html>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Multiple controller
In angularjs we have learnt how to create controller now we are going to add multiple controllers in
single module. We can add multiple controllers to the single module. So I am going to create new
controller with the name of trainer in which I want to show the trainer details.
9
var angmodule= angular.module('mymodule',[])
.controller('course', function($scope){
$scope.coursename='Asp.net';$scope.fees='15000'; });
angmodule.controller("trainer", function($scope){
var trainerdetail=[
{ name:'isha', age:'27' },{ name:'avinash', age:'32' },
{ name:'priya', age:'34' }];
$scope.trainerdata=trainerdetail;});
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:-www.techaltum.com
JSON Object
JSON stands for JavaScript Object Notation. In JSON object, we store value in
key value pair in the following manner
Syntax of JSON Object
{ ‘key’:’value’, ‘key’:’value’ }
10
Example of JSON Object
var x={ ‘id’:101, ‘name’:’isha’, ‘age’:29 }
We can also store the array of JSON Object in the following manner:-
var x=[{ ‘id’:101, ‘name’:’isha’, ‘age’:29 }, {‘id’:102, ‘name’:’avinash’, ‘age’:33 }]
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-repeat in angularjs
Ng-repeat is one of the directive in angularjs. It is used to looping the given object. When we need to display, the set of
html in repeated mode with some data or collection then we can use ng-repeat directive.
11
<head>
<script src="angular.js"></script>
<script>
var p=
angular.module('mymodule',[]).controller('courses',functi
on($scope){
var result=[{ name:'Asp.net', fees:'15000'}
,{ name:'php', fees:'17000'},
{ name:'AngularJS', fees:'8000' } ] ;
$scope.data=result;
});
</script>
/head>
<body ng-app="mymodule">
<div ng-controller="courses">
<table border="1">
<tr> <td>Course Name</td> <td>Course
Fees</td> </tr>
<tr ng-repeat="x in data">
<td> {{x.name}} </td> <td> {{x.fees}} </td>
</tr>
</table> </div> </body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-repeat with track by
Let us take another example. Suppose we have following index array with repeating records:-
12
<script>
var x=angular.module("module1",[]);
x.controller("con1",function($scope){
$scope.result=[2,4,4,4,5,6,7]; });
</script>
Now traverse this array using ng-repeat and you will
get following error:-
To traverse duplicate records in ng-repeat we
will use $index in the following code:-
<body ng-app="module1">
<div ng-controller="con1">
<div ng-repeat="k in result track by
$index">
<p>{{k}}</p>
</div>
</div>
</body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-model in angularJS
Ng-model is used to bind input fields, select and textarea with model and we can use this model in page. Ng-model
provides the facility of two-way data binding.
13
<head>
<script src="angular.min.js"></script>
</head>
<body ng-app>
<input type="text" ng-model="t1">
<p>{{ t1 }}</p>
</body>
Example of Ng-model
We have following textbox. And we want as user will type the data it will show in paragraph tag. If we have to do this task
without angularJS then we have to use JavaScript and need to use the event on which it will display textbox text in
paragraph. But with the help of ng-model we will bind this input control with model and after that we can use this model
anywhere.
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-model example with input fields
14
<body ng-app>
<div>
<input type="text" ng-model='tbox'>
<br>
Male<input type='radio' name='n1' value='male' ng-model='tradio'>
Female<input type='radio' name='n1' value='female' ng-model='tradio'>
<br>
<select ng-model='tselect'> <option>18</option> <option>19</option> <option>20</option>
</select><br>
<input type="checkbox" ng-true-value="'books'" ng-false-value='' ng-model='ch1.tcheck1' > books
<input type="checkbox" ng-true-value="'food'" ng-false-value='' ng-model='ch1.tcheck2' > food
<input type="checkbox" ng-true-value="'mobile'" ng-false-value='' ng-model='ch1.tcheck3' > mobile </div>
<div> Name :- {{tbox}} <br> gender :- {{tradio}} <br> age :- {{tselect}} <br>
products are :-<div ng-repeat='x in ch1'>{{x}}</div></div>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-init in angularJS
Ng-init directive is used to initialize a variable, which will allows evaluating an expression in given scope. According to
angular official document, this directive is abused as it adds unnecessary business logic in the application. Still to evaluate
an expression we required that directive.
In the following example, I have created ng-init, assign value in it, and simply print it.
15
<body ng-app ng-init="name='isha'">
<div> {{name}} </div>
</body>
We can also bind this ng-init variable in ng-model and can use it in application in the following manner
<body ng-app ng-init="number=‘6'">
<div>
<input type="text" ng-model="number">
<p>Square is {{number*number}} </p>
</div>
</body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-if in angularJS
Ng-if directive is condition based directive which removes or recreates the DOM portion according to
condition. It evaluates expression as true or false. If ng-if evaluates to a false it will remove from the DOM
element and if it is true, then element is reinserted into the DOM. We can also use and (&&) or (||) operator in
ng-if to evaluate the expression. We can also use nested ng-if in angularjs.
16
<body ng-app>
Enter your number: - <input type="text" ng-
model="n1" placeholder="9">
<div ng-if="n1%2=='0'">
<p>Even Number</p>
</div>
<div ng-if="n1%2! ='0'">
<p>Odd Number</p>
</div>
<script src="angular.js"></script>
</body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-Switch in angularJS
Ng-switch is conditional directives which swap (show and hide) DOM elements according to expression.
We use ng-switch-when to check conditions and ng-switch-default to put default condition.
17
<head>
<title>Untitled Document</title>
<meta charset="UTF-8">
<script src="angular.js"></script>
</head>
<body ng-app>
<input type="text" ng-model="n1">
<div ng-switch="n1">
<div ng-switch-when="a">It is vowel</div>
<div ng-switch-when="i">It is vowel</div>
<div ng-switch-when="e">It is vowel</div>
<div ng-switch-when="o">It is vowel</div>
<div ng-switch-when="u">It is vowel</div>
<div ng-switch-default>It is constant</div>
</div>
</body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-show and ng-hide
These both directives are used to manage the visibility of html controls. Both directives take true and false
value to display or hide the html control.
18
<head>
<title>ng-hide and ng-show example</title>
<script src="angular.min.js"></script>
</head>
<body ng-app>
<input type="checkbox" ng-
model="textbox" value="show textbox"/>Show
Textbox
<br> <input type="text" ng-
show="textbox"/>
</body>
Example of ng-show
In this example we have created checkbox and bind it with ng-
model. And used this ng-model in ng-show directives. When page
load it would not be true so it will not display textbox. But when we
checked the checkbox then it would be true and it will display the
textbox.
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Example of ng-hide
19
<input type="checkbox" ng-
model="textbox" value="show
textbox"/>Hide Textbox
<br>
<input type="text" ng-hide="textbox"/>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-include in angularjs
This directive is used to add external html files into application. This directive helps us to create common
page of website.
20
Create a html file for header menu
Header.html
<div><a href="home.html">Home</a> |
<a href="about.html">About us</a> |
<a href="contact.html">contact</a>|
<a href="login.html">Login</a>
</div>
Example of ng-include
<head>
<script src="angular.min.js"></script>
</head>
<body ng-app>
<div id="headermenu" ng-include="'header.html'"></div>
<div>This is home page dummy content</div>
</body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-src in angularjs
Ng-src directive is used to bind dynamic image url. When we use src at img tag it will not work properly as it
will fetch image before angularjs replace expression with url and 404 error occurred.
21
<head><script src="angular.js"></script>
<script>
var x=angular.module("module1",[]);
x.controller("con1",function($scope){
$scope.data=[
{id:101,name:'isha',age:28,image:'ng-1.jpg'},
{id:102,name:'neha',age:53, image:'ng-2.jpg'},
{id:103,name:'seema',age:56, image:'ng-1.jpg'},
{id:104,name:'avinash',age:32, image:'ng-2.jpg'},
{id:105,name:'ranjay',age:25, image:'ng-1.jpg'}
]; });</script> </head>
Example of ng-src
<body ng-app="module1">
<div ng-controller="con1"><table border="1">
<tr><th>S.No</th><th>Employee
Id</th><th>Employee Name</th><th>Employee
Age</th><th>Marks</th><th>Picutre</th></tr>
<tr ng-repeat="p in data" >
<td>{{$index+1}}</td> <td>{{p.id}}</td>
<td>{{p.name}}</td> <td>{{p.age}}</td>
<td>{{p.marks | m1}}</td> <td><img
src='{{p.image}}' alt={{p.name}}></td></tr>
</table> </div></body>
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-src in angularjs
When we will execute this code, it will generate 404 error, as it will try to load p.image, which is not available.
Image will be loaded but with 404 error which is not good practice.
22
Now replace src with ng-src and again execute the code.
Address :- 501, Om Complex, 5th Floor, Naya Bans,
Sec-15, Noida-201301 (U.P.)
Tel: +91(0)-0120-4280181,9015041412
Email: info@techaltum.com Website:- www.techaltum.com
Ng-click in angularjs
Ng-click provides the custom behaviour when an element is clicked. When elements clicked, it will call the
event handler function, which bind to ng-click.
23
<head>
<script src="angular.js"></script>
<script>
var x =angular.module('abc',[])
x.controller('abc1',function($scope){
$scope.add=function(n1,n2){
$scope.data=parseInt(n1)+parseInt(n2);
}
});
</script> </head>
Example of ng-click
<body ng-app='abc'>
<div ng-controller='abc1'>
enter 1st value: <input type="text" ng-
model='n1'><br>
enter 2nd value: <input type="text" ng-
model='n2'><br>
<input type="button" value="sum" ng-
click='add(n1,n2)'>
<div> {{data}} </div> </div>
</body>

More Related Content

Similar to Tech Altum :- Angular introduction, Installation and directives

Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
Adam Moore
 

Similar to Tech Altum :- Angular introduction, Installation and directives (20)

Angular js
Angular jsAngular js
Angular js
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
AangularJS Framework
AangularJS FrameworkAangularJS Framework
AangularJS Framework
 
Angular Interview Questions & Answers
Angular Interview Questions & AnswersAngular Interview Questions & Answers
Angular Interview Questions & Answers
 
AngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPIAngularJS Fundamentals + WebAPI
AngularJS Fundamentals + WebAPI
 
はじめてのAngular2
はじめてのAngular2はじめてのAngular2
はじめてのAngular2
 
Angular Js Basics
Angular Js BasicsAngular Js Basics
Angular Js Basics
 
AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014AngularJs Workshop SDP December 28th 2014
AngularJs Workshop SDP December 28th 2014
 
Angular Presentation
Angular PresentationAngular Presentation
Angular Presentation
 
Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...Single Page Applications Workshop Part II: Single Page Applications using Ang...
Single Page Applications Workshop Part II: Single Page Applications using Ang...
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
Angular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdfAngular Interview Questions-PDF.pdf
Angular Interview Questions-PDF.pdf
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
angularJs Workshop
angularJs WorkshopangularJs Workshop
angularJs Workshop
 
Angular js slides
Angular js slidesAngular js slides
Angular js slides
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
Angular js
Angular jsAngular js
Angular js
 

Recently uploaded

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Modernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using BallerinaModernizing Legacy Systems Using Ballerina
Modernizing Legacy Systems Using Ballerina
 
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data PlatformLess Is More: Utilizing Ballerina to Architect a Cloud Data Platform
Less Is More: Utilizing Ballerina to Architect a Cloud Data Platform
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Simplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptxSimplifying Mobile A11y Presentation.pptx
Simplifying Mobile A11y Presentation.pptx
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Decarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational PerformanceDecarbonising Commercial Real Estate: The Role of Operational Performance
Decarbonising Commercial Real Estate: The Role of Operational Performance
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Quantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation ComputingQuantum Leap in Next-Generation Computing
Quantum Leap in Next-Generation Computing
 
Navigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern EnterpriseNavigating Identity and Access Management in the Modern Enterprise
Navigating Identity and Access Management in the Modern Enterprise
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
TEST BANK For Principles of Anatomy and Physiology, 16th Edition by Gerard J....
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 

Tech Altum :- Angular introduction, Installation and directives

  • 1. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com What is AngularJS AngularJS is an open source JavaScript framework to develop web based applications. AngularJS is having two versions i.e. AngularJS 1 and AngularJS 2. Advantage of AngularJS  Easy to Code  Best framework to create SPA(Single Page Application)  It supports MVC(Model View Controller) concept  It supports routing  It provides dependency injection 1
  • 2. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com How to Set AngularJS environment As we know AngularJS is JavaScript framework so first we need to add javascript file which AngularJS is using. It is using angular.js file to work. Go to the angularJS official website to download angular.js file https://angularjs.org/ How to Add angular.js in View We need to add the Script tag in HTML file (Any UI which you are using) in which we add source of angular.js file. <script src="angular.min.js"></script> 2
  • 3. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com Directives Directives in angularJS extends HTML code to provide new behaviour. In angularJS we use ng keyword which means angular. All directives in angularJS starts from ng. 3 Types of Directives Built-in Custom
  • 4. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com Ng-app Directives ng-app directive is the beginning directive of angularJS. It is used to auto bootstrap angularJS application. We generally use this directive at root level like inside html tag or in body tag. When angularJS application loads it will first search for ng-app directives. In other words, you can say that it is used to inform angularJS framework from where it has to initiate. Syntax of ng-app Add ng-app tag in body tag in the following manner:- <body data-ng-app> </body> 4
  • 5. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com Binding Expression In angularJS we use {{ }} for binding expression. For any kind of evaluation, we can perform inside this binding expression Example of ng-app <body ng-app> <p>The sum of 20 and 30 is </p> <p>{{20+30}}</p> </body> In this example it will simply evaluate the sum and display. Note :- We use data-ng-app directives to validate HTML5. it will consider data-ng-app as custom attribute. 5
  • 6. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com Module in AngularJS Module in angularjs is just like container which is having the business logics, controllers, services etc. How to declare Module To create module, we use angular.module function. In this function we pass first parameter as module name and second parameter is dependent module. If do not have any dependent module then we can leave it as blank. var angmodule= angular.module('mymodule',[ ]) in this code mymodule is module name and empty array represents that there is no dependency on module. We can use this module with ng-app in the following manner ng-app="mymodule" 6
  • 7. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com MVC Architecture MVC Stands for Model View Controller. In MVC view represents the user interface and model is the data. Both view and model is independent to each other. Controller is like bridge between model and view. What is Controller In angularJS controller is JavaScript function object. We need to create controller inside module. We use ng-controller directive to add controller. 7 What is $scope $scope is the kind of object which represents the application model. It is used to pass data between view and controller. We can add properties and function in this scope and we can use it in View.
  • 8. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Example of MVC In this example we are creating a controller in which we need to pass data to view i.e. the name of the course along with the fees. So we will write the code in the following manner 8 <!DOCTYPE html> <html> <head> <script src="angular.min.js"></script> <script> var angmodule= angular.module('mymodule',[]).controller('course', function($scope){ $scope.coursename='Asp.net'; $scope.fees='15000'; }); </script> </head> <body ng-app="mymodule"> <div ng-controller="course"> <p>Course: {{ coursename }}</p> <p>Fees: {{ fees }}</p> </div> </body> </html>
  • 9. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Multiple controller In angularjs we have learnt how to create controller now we are going to add multiple controllers in single module. We can add multiple controllers to the single module. So I am going to create new controller with the name of trainer in which I want to show the trainer details. 9 var angmodule= angular.module('mymodule',[]) .controller('course', function($scope){ $scope.coursename='Asp.net';$scope.fees='15000'; }); angmodule.controller("trainer", function($scope){ var trainerdetail=[ { name:'isha', age:'27' },{ name:'avinash', age:'32' }, { name:'priya', age:'34' }]; $scope.trainerdata=trainerdetail;});
  • 10. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:-www.techaltum.com JSON Object JSON stands for JavaScript Object Notation. In JSON object, we store value in key value pair in the following manner Syntax of JSON Object { ‘key’:’value’, ‘key’:’value’ } 10 Example of JSON Object var x={ ‘id’:101, ‘name’:’isha’, ‘age’:29 } We can also store the array of JSON Object in the following manner:- var x=[{ ‘id’:101, ‘name’:’isha’, ‘age’:29 }, {‘id’:102, ‘name’:’avinash’, ‘age’:33 }]
  • 11. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-repeat in angularjs Ng-repeat is one of the directive in angularjs. It is used to looping the given object. When we need to display, the set of html in repeated mode with some data or collection then we can use ng-repeat directive. 11 <head> <script src="angular.js"></script> <script> var p= angular.module('mymodule',[]).controller('courses',functi on($scope){ var result=[{ name:'Asp.net', fees:'15000'} ,{ name:'php', fees:'17000'}, { name:'AngularJS', fees:'8000' } ] ; $scope.data=result; }); </script> /head> <body ng-app="mymodule"> <div ng-controller="courses"> <table border="1"> <tr> <td>Course Name</td> <td>Course Fees</td> </tr> <tr ng-repeat="x in data"> <td> {{x.name}} </td> <td> {{x.fees}} </td> </tr> </table> </div> </body>
  • 12. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-repeat with track by Let us take another example. Suppose we have following index array with repeating records:- 12 <script> var x=angular.module("module1",[]); x.controller("con1",function($scope){ $scope.result=[2,4,4,4,5,6,7]; }); </script> Now traverse this array using ng-repeat and you will get following error:- To traverse duplicate records in ng-repeat we will use $index in the following code:- <body ng-app="module1"> <div ng-controller="con1"> <div ng-repeat="k in result track by $index"> <p>{{k}}</p> </div> </div> </body>
  • 13. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-model in angularJS Ng-model is used to bind input fields, select and textarea with model and we can use this model in page. Ng-model provides the facility of two-way data binding. 13 <head> <script src="angular.min.js"></script> </head> <body ng-app> <input type="text" ng-model="t1"> <p>{{ t1 }}</p> </body> Example of Ng-model We have following textbox. And we want as user will type the data it will show in paragraph tag. If we have to do this task without angularJS then we have to use JavaScript and need to use the event on which it will display textbox text in paragraph. But with the help of ng-model we will bind this input control with model and after that we can use this model anywhere.
  • 14. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-model example with input fields 14 <body ng-app> <div> <input type="text" ng-model='tbox'> <br> Male<input type='radio' name='n1' value='male' ng-model='tradio'> Female<input type='radio' name='n1' value='female' ng-model='tradio'> <br> <select ng-model='tselect'> <option>18</option> <option>19</option> <option>20</option> </select><br> <input type="checkbox" ng-true-value="'books'" ng-false-value='' ng-model='ch1.tcheck1' > books <input type="checkbox" ng-true-value="'food'" ng-false-value='' ng-model='ch1.tcheck2' > food <input type="checkbox" ng-true-value="'mobile'" ng-false-value='' ng-model='ch1.tcheck3' > mobile </div> <div> Name :- {{tbox}} <br> gender :- {{tradio}} <br> age :- {{tselect}} <br> products are :-<div ng-repeat='x in ch1'>{{x}}</div></div>
  • 15. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-init in angularJS Ng-init directive is used to initialize a variable, which will allows evaluating an expression in given scope. According to angular official document, this directive is abused as it adds unnecessary business logic in the application. Still to evaluate an expression we required that directive. In the following example, I have created ng-init, assign value in it, and simply print it. 15 <body ng-app ng-init="name='isha'"> <div> {{name}} </div> </body> We can also bind this ng-init variable in ng-model and can use it in application in the following manner <body ng-app ng-init="number=‘6'"> <div> <input type="text" ng-model="number"> <p>Square is {{number*number}} </p> </div> </body>
  • 16. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-if in angularJS Ng-if directive is condition based directive which removes or recreates the DOM portion according to condition. It evaluates expression as true or false. If ng-if evaluates to a false it will remove from the DOM element and if it is true, then element is reinserted into the DOM. We can also use and (&&) or (||) operator in ng-if to evaluate the expression. We can also use nested ng-if in angularjs. 16 <body ng-app> Enter your number: - <input type="text" ng- model="n1" placeholder="9"> <div ng-if="n1%2=='0'"> <p>Even Number</p> </div> <div ng-if="n1%2! ='0'"> <p>Odd Number</p> </div> <script src="angular.js"></script> </body>
  • 17. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-Switch in angularJS Ng-switch is conditional directives which swap (show and hide) DOM elements according to expression. We use ng-switch-when to check conditions and ng-switch-default to put default condition. 17 <head> <title>Untitled Document</title> <meta charset="UTF-8"> <script src="angular.js"></script> </head> <body ng-app> <input type="text" ng-model="n1"> <div ng-switch="n1"> <div ng-switch-when="a">It is vowel</div> <div ng-switch-when="i">It is vowel</div> <div ng-switch-when="e">It is vowel</div> <div ng-switch-when="o">It is vowel</div> <div ng-switch-when="u">It is vowel</div> <div ng-switch-default>It is constant</div> </div> </body>
  • 18. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-show and ng-hide These both directives are used to manage the visibility of html controls. Both directives take true and false value to display or hide the html control. 18 <head> <title>ng-hide and ng-show example</title> <script src="angular.min.js"></script> </head> <body ng-app> <input type="checkbox" ng- model="textbox" value="show textbox"/>Show Textbox <br> <input type="text" ng- show="textbox"/> </body> Example of ng-show In this example we have created checkbox and bind it with ng- model. And used this ng-model in ng-show directives. When page load it would not be true so it will not display textbox. But when we checked the checkbox then it would be true and it will display the textbox.
  • 19. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Example of ng-hide 19 <input type="checkbox" ng- model="textbox" value="show textbox"/>Hide Textbox <br> <input type="text" ng-hide="textbox"/>
  • 20. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-include in angularjs This directive is used to add external html files into application. This directive helps us to create common page of website. 20 Create a html file for header menu Header.html <div><a href="home.html">Home</a> | <a href="about.html">About us</a> | <a href="contact.html">contact</a>| <a href="login.html">Login</a> </div> Example of ng-include <head> <script src="angular.min.js"></script> </head> <body ng-app> <div id="headermenu" ng-include="'header.html'"></div> <div>This is home page dummy content</div> </body>
  • 21. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-src in angularjs Ng-src directive is used to bind dynamic image url. When we use src at img tag it will not work properly as it will fetch image before angularjs replace expression with url and 404 error occurred. 21 <head><script src="angular.js"></script> <script> var x=angular.module("module1",[]); x.controller("con1",function($scope){ $scope.data=[ {id:101,name:'isha',age:28,image:'ng-1.jpg'}, {id:102,name:'neha',age:53, image:'ng-2.jpg'}, {id:103,name:'seema',age:56, image:'ng-1.jpg'}, {id:104,name:'avinash',age:32, image:'ng-2.jpg'}, {id:105,name:'ranjay',age:25, image:'ng-1.jpg'} ]; });</script> </head> Example of ng-src <body ng-app="module1"> <div ng-controller="con1"><table border="1"> <tr><th>S.No</th><th>Employee Id</th><th>Employee Name</th><th>Employee Age</th><th>Marks</th><th>Picutre</th></tr> <tr ng-repeat="p in data" > <td>{{$index+1}}</td> <td>{{p.id}}</td> <td>{{p.name}}</td> <td>{{p.age}}</td> <td>{{p.marks | m1}}</td> <td><img src='{{p.image}}' alt={{p.name}}></td></tr> </table> </div></body>
  • 22. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-src in angularjs When we will execute this code, it will generate 404 error, as it will try to load p.image, which is not available. Image will be loaded but with 404 error which is not good practice. 22 Now replace src with ng-src and again execute the code.
  • 23. Address :- 501, Om Complex, 5th Floor, Naya Bans, Sec-15, Noida-201301 (U.P.) Tel: +91(0)-0120-4280181,9015041412 Email: info@techaltum.com Website:- www.techaltum.com Ng-click in angularjs Ng-click provides the custom behaviour when an element is clicked. When elements clicked, it will call the event handler function, which bind to ng-click. 23 <head> <script src="angular.js"></script> <script> var x =angular.module('abc',[]) x.controller('abc1',function($scope){ $scope.add=function(n1,n2){ $scope.data=parseInt(n1)+parseInt(n2); } }); </script> </head> Example of ng-click <body ng-app='abc'> <div ng-controller='abc1'> enter 1st value: <input type="text" ng- model='n1'><br> enter 2nd value: <input type="text" ng- model='n2'><br> <input type="button" value="sum" ng- click='add(n1,n2)'> <div> {{data}} </div> </div> </body>