SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Angular Directive
Filter and Routing
JAGRITI SRIVASTAVA
Common Angular Directives
 ng-app
 ng-controller
 ng-view
 ng-init
 ng-model
 ng-repeat
 ng-show
 ng-hide
 ng-include
 ng-init
 Initializes an AngularJS Application data.
 It is used to put values to the variables to be used in the application
 ng-app
 Defines the root element.
 Automatically initializes or bootstraps the application when web page containing
AngularJS Application is loaded.
 Also used to load various AngularJS modules in AngularJS Application.
<div ng-app = "" ng-init = "countries = [{locale:'en-US',name:'United States'},
{locale:'en-GB',name:'United Kingdom'},
{locale:'en-FR',name:'France'}]">
... </div>
 ng-model
 This directive binds the values of AngularJS application data to HTML input
controls.
 ng-repeat
 ng-repeat directive repeats html elements for each item in a collection.
<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>
 Example
<html>
<head> <title>AngularJS Directives</title>
</head>
<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 = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</body>
</html>
ng-hide : hides element when checkbox is clicked
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="">
Hide HTML: <input type="checkbox" ng-model="myVar">
<div ng-hide="myVar">
<h1>Welcome</h1>
<p>Welcome to my home.</p>
</div>
</body>
</html>
ng-show : shows certain element when checkbox is clicked
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="">
Show HTML: <input type="checkbox" ng-model="myVar">
<div ng-show="myVar">
<h1>Welcome</h1>
<p>Welcome to my home.</p>
</div>
</body>
</html>
ng-include ....to include template
 Html doesn’t support embedding html page into html page
 But angularjs provides functionality of embedding html into another html page
using ng-include
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="">
<div ng-include="'myFile.htm'"></div>
</body>
</html>
Index.html
Filters
 They format the value of an expression for displaying to the end user
 They are added to expressions by using the pipe character | , followed by a
filter
 It can be used in view templates as well as in controller.
 More than one filters can be used.
 Some built-in filters are
 Currency
 Uppercase
 Date
 Lowercase
 search
uppercase and lowercase
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="personCtrl">
<p>The name is {{ lastName | uppercase }}</p>
<p>The name is {{ lastName | lowercase }}</p>
</div>
<script>
angular.module('myApp', []).controller('personCtrl', function($scope) {
$scope.firstName = "John",
$scope.lastName = "Doe"
});
</script>
</body>
</html>
Currency<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="costCtrl">
<h1>Price: {{ price | currency }}</h1>
<h1>Price: {{ price | currency :"Rs"}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('costCtrl', function($scope) {
$scope.price = 58;
});
</script>
<p>The currency filter formats a number to a currency format.</p>
</body>
</html>
Date filter
 By default, the format is "MMM d, y" (Jan 5, 2016).
 Date format can be changed as
 "short" same as "M/d/yy h:mm a" (1/5/16 9:05 AM)
 "medium" same as "MMM d, y h:mm:ss a" (Jan 5, 2016 9:05:05 AM)
 "shortDate" same as "M/d/yy" (1/5/16)
 "mediumDate" same as "MMM d, y" (Jan 5, 2016)
 "longDate" same as "MMMM d, y" (January 5, 2016)
 "fullDate" same as "EEEE, MMMM d, y" (Tuesday, January 5, 2016)
 "shortTime" same as "h:mm a" (9:05 AM)
 "mediumTime" same as "h:mm:ss a" (9:05:05 AM)
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="datCtrl">
<p>Date = {{ today | date }}</p>
<p>Date = {{ today | date : "dd.MM.y"}}</p>
<p>Date with time = {{ today | date :" M/d/yy h:mm a"}}</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('datCtrl', function($scope) {
$scope.today = new Date();
});
</script>
<p>The date filter formats a date object to a readable format.</p>
</body>
</html>
Filter : filter
 The filter filter selects a subset of an array.
 The filter filter can only be used on arrays, and it returns an array containing
only the matching items.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="namesCtrl">
<ul>
<li ng-repeat="x in names | filter : 'a'">
{{ x }}
</li>
</ul>
</div>
<script>
angular.module('myApp', []).controller('namesCtrl', function($scope) {
$scope.names = [
'Jani', 'Gusto','Ford','BMW','Santro'
];
});
</script>
<p>This example displays only the names containing the letter "i".</p>
</body>
</html>
Custom Filter
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"><
/script>
<body>
<ul ng-app="myApp" ng-controller="namesCtrl">
<li ng-repeat="x in names">
{{x | myFormat}}
</li>
</ul>
<script>
var app = angular.module('myApp', []);
app.filter('myFormat', function() {
return function(x) {
var i, c, txt = "";
for (i = 0; i < x.length; i++) {
c = x[i];
if (i % 2 == 0) {
c = c.toUpperCase();
}
txt += c;
}
return txt;
};
});
app.controller('namesCtrl', function($scope) {
$scope.names = [ 'Jani','Carl', 'Hege', 'Joe', 'Birgit','Mary', 'Kai' ];
});
</script>
<p>Make your own filters.</p>
<p>This filter, called "myFormat", will uppercase every other character.</p>
</body>
</html>
Routing
 To navigate between multiple pages but make application work as single page
application routing is used.
 Since html page can not embed another html page in it routing in ANGULARJS
provides such functionality.
 To make routing work the angular app must run on server
 So to run angular app in server
 Install xampp
 Create angular app
 Add angular-route.js file to your application to enable routing.
 Add your app inside xampp/htdocs
 Run the application
Routing example :
 create index.html
 Add angular-route.js in the script
 Main, City 1, City 2 to navigate between all three pages called by them
<body ng-app="myApp">
<p><a href="#/!">Main</a></p>
<a href="#!london">City 1</a>
<a href="#!paris">City 2</a>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm“  redirects to main.htm when nothing is
clicked
})
.when("/london", {
templateUrl : "london.htm“  redirects to london.htm when City 1 is
clicked
})
.when("/paris", {
templateUrl : "paris.htm“  redirects to paris.htm when City 2 is
clicked
});
});
</script>
Angular directive filter and routing

Weitere ähnliche Inhalte

Was ist angesagt?

jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
adamlogic
 

Was ist angesagt? (20)

jQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a TreejQuery and Rails, Sitting in a Tree
jQuery and Rails, Sitting in a Tree
 
Dart and AngularDart
Dart and AngularDartDart and AngularDart
Dart and AngularDart
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
Angular js routing options
Angular js routing optionsAngular js routing options
Angular js routing options
 
AngularJS Basics with Example
AngularJS Basics with ExampleAngularJS Basics with Example
AngularJS Basics with Example
 
AngularJS Routing
AngularJS RoutingAngularJS Routing
AngularJS Routing
 
Jquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript BasicsJquery Complete Presentation along with Javascript Basics
Jquery Complete Presentation along with Javascript Basics
 
Building an End-to-End AngularJS Application
Building an End-to-End AngularJS ApplicationBuilding an End-to-End AngularJS Application
Building an End-to-End AngularJS Application
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
Top 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers MakeTop 10 Mistakes AngularJS Developers Make
Top 10 Mistakes AngularJS Developers Make
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
AngularJS Framework
AngularJS FrameworkAngularJS Framework
AngularJS Framework
 
Workshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte IWorkshop 12: AngularJS Parte I
Workshop 12: AngularJS Parte I
 
Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
Angular js is the future. maybe. @ ConFoo 2014 in Montreal (CA)
 
Angular js
Angular jsAngular js
Angular js
 
J Query Presentation
J Query PresentationJ Query Presentation
J Query Presentation
 
AngularJS best-practices
AngularJS best-practicesAngularJS best-practices
AngularJS best-practices
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
Angularjs Anti-patterns
Angularjs Anti-patternsAngularjs Anti-patterns
Angularjs Anti-patterns
 

Ähnlich wie Angular directive filter and routing

Private slideshow
Private slideshowPrivate slideshow
Private slideshow
sblackman
 

Ähnlich wie Angular directive filter and routing (20)

AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle StudiosAngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
AngularJs Superheroic JavaScript MVW Framework Services by Miracle Studios
 
Angular js
Angular jsAngular js
Angular js
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
Introduction to angular js
Introduction to angular jsIntroduction to angular js
Introduction to angular js
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014AngularJS Mobile Warsaw 20-10-2014
AngularJS Mobile Warsaw 20-10-2014
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
AngularJS interview questions
AngularJS interview questionsAngularJS interview questions
AngularJS interview questions
 
Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics Angular server side rendering - Strategies & Technics
Angular server side rendering - Strategies & Technics
 
Private slideshow
Private slideshowPrivate slideshow
Private slideshow
 
Basics of AngularJS
Basics of AngularJSBasics of AngularJS
Basics of AngularJS
 
Dive into AngularJS and directives
Dive into AngularJS and directivesDive into AngularJS and directives
Dive into AngularJS and directives
 
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 js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013Angular js - 4developers 12 kwietnia 2013
Angular js - 4developers 12 kwietnia 2013
 
Test upload
Test uploadTest upload
Test upload
 
Course CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.jsCourse CodeSchool - Shaping up with Angular.js
Course CodeSchool - Shaping up with Angular.js
 
Taking your Web App for a walk
Taking your Web App for a walkTaking your Web App for a walk
Taking your Web App for a walk
 

Mehr von jagriti srivastava

Mehr von jagriti srivastava (14)

Map reduce with big data
Map reduce with big dataMap reduce with big data
Map reduce with big data
 
Oyo rooms
Oyo roomsOyo rooms
Oyo rooms
 
Information system of amazon
Information system of amazonInformation system of amazon
Information system of amazon
 
JavaScript Canvas
JavaScript CanvasJavaScript Canvas
JavaScript Canvas
 
Variable and Methods in Java
Variable and Methods in JavaVariable and Methods in Java
Variable and Methods in Java
 
Component diagram and Deployment Diagram
Component diagram and Deployment DiagramComponent diagram and Deployment Diagram
Component diagram and Deployment Diagram
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Form validation and animation
Form validation and animationForm validation and animation
Form validation and animation
 
Starting with angular js
Starting with angular js Starting with angular js
Starting with angular js
 
Angular introduction basic
Angular introduction basicAngular introduction basic
Angular introduction basic
 
Scannerclass
ScannerclassScannerclass
Scannerclass
 
Programming Workshop
Programming WorkshopProgramming Workshop
Programming Workshop
 
Java Nested class Concept
Java Nested class ConceptJava Nested class Concept
Java Nested class Concept
 
Java , A brief Introduction
Java , A brief Introduction Java , A brief Introduction
Java , A brief Introduction
 

Kürzlich hochgeladen

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 

Angular directive filter and routing

  • 1. Angular Directive Filter and Routing JAGRITI SRIVASTAVA
  • 2. Common Angular Directives  ng-app  ng-controller  ng-view  ng-init  ng-model  ng-repeat  ng-show  ng-hide  ng-include
  • 3.  ng-init  Initializes an AngularJS Application data.  It is used to put values to the variables to be used in the application  ng-app  Defines the root element.  Automatically initializes or bootstraps the application when web page containing AngularJS Application is loaded.  Also used to load various AngularJS modules in AngularJS Application. <div ng-app = "" ng-init = "countries = [{locale:'en-US',name:'United States'}, {locale:'en-GB',name:'United Kingdom'}, {locale:'en-FR',name:'France'}]"> ... </div>
  • 4.  ng-model  This directive binds the values of AngularJS application data to HTML input controls.  ng-repeat  ng-repeat directive repeats html elements for each item in a collection. <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>
  • 5.  Example <html> <head> <title>AngularJS Directives</title> </head> <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 = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </body> </html>
  • 6. ng-hide : hides element when checkbox is clicked <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body ng-app=""> Hide HTML: <input type="checkbox" ng-model="myVar"> <div ng-hide="myVar"> <h1>Welcome</h1> <p>Welcome to my home.</p> </div> </body> </html>
  • 7. ng-show : shows certain element when checkbox is clicked <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body ng-app=""> Show HTML: <input type="checkbox" ng-model="myVar"> <div ng-show="myVar"> <h1>Welcome</h1> <p>Welcome to my home.</p> </div> </body> </html>
  • 8. ng-include ....to include template  Html doesn’t support embedding html page into html page  But angularjs provides functionality of embedding html into another html page using ng-include <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body ng-app=""> <div ng-include="'myFile.htm'"></div> </body> </html> Index.html
  • 9. Filters  They format the value of an expression for displaying to the end user  They are added to expressions by using the pipe character | , followed by a filter  It can be used in view templates as well as in controller.  More than one filters can be used.  Some built-in filters are  Currency  Uppercase  Date  Lowercase  search
  • 10. uppercase and lowercase <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="personCtrl"> <p>The name is {{ lastName | uppercase }}</p> <p>The name is {{ lastName | lowercase }}</p> </div> <script> angular.module('myApp', []).controller('personCtrl', function($scope) { $scope.firstName = "John", $scope.lastName = "Doe" }); </script> </body> </html>
  • 11. Currency<!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="costCtrl"> <h1>Price: {{ price | currency }}</h1> <h1>Price: {{ price | currency :"Rs"}}</h1> </div> <script> var app = angular.module('myApp', []); app.controller('costCtrl', function($scope) { $scope.price = 58; }); </script> <p>The currency filter formats a number to a currency format.</p> </body> </html>
  • 12. Date filter  By default, the format is "MMM d, y" (Jan 5, 2016).  Date format can be changed as  "short" same as "M/d/yy h:mm a" (1/5/16 9:05 AM)  "medium" same as "MMM d, y h:mm:ss a" (Jan 5, 2016 9:05:05 AM)  "shortDate" same as "M/d/yy" (1/5/16)  "mediumDate" same as "MMM d, y" (Jan 5, 2016)  "longDate" same as "MMMM d, y" (January 5, 2016)  "fullDate" same as "EEEE, MMMM d, y" (Tuesday, January 5, 2016)  "shortTime" same as "h:mm a" (9:05 AM)  "mediumTime" same as "h:mm:ss a" (9:05:05 AM)
  • 13. <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="datCtrl"> <p>Date = {{ today | date }}</p> <p>Date = {{ today | date : "dd.MM.y"}}</p> <p>Date with time = {{ today | date :" M/d/yy h:mm a"}}</p> </div> <script> var app = angular.module('myApp', []); app.controller('datCtrl', function($scope) { $scope.today = new Date(); }); </script> <p>The date filter formats a date object to a readable format.</p> </body> </html>
  • 14. Filter : filter  The filter filter selects a subset of an array.  The filter filter can only be used on arrays, and it returns an array containing only the matching items. <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script> <body> <div ng-app="myApp" ng-controller="namesCtrl"> <ul> <li ng-repeat="x in names | filter : 'a'"> {{ x }} </li> </ul> </div> <script> angular.module('myApp', []).controller('namesCtrl', function($scope) { $scope.names = [ 'Jani', 'Gusto','Ford','BMW','Santro' ]; }); </script> <p>This example displays only the names containing the letter "i".</p> </body> </html>
  • 15. Custom Filter <!DOCTYPE html> <html> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">< /script> <body> <ul ng-app="myApp" ng-controller="namesCtrl"> <li ng-repeat="x in names"> {{x | myFormat}} </li> </ul> <script>
  • 16. var app = angular.module('myApp', []); app.filter('myFormat', function() { return function(x) { var i, c, txt = ""; for (i = 0; i < x.length; i++) { c = x[i]; if (i % 2 == 0) { c = c.toUpperCase(); } txt += c; } return txt; }; }); app.controller('namesCtrl', function($scope) { $scope.names = [ 'Jani','Carl', 'Hege', 'Joe', 'Birgit','Mary', 'Kai' ]; }); </script> <p>Make your own filters.</p> <p>This filter, called "myFormat", will uppercase every other character.</p> </body> </html>
  • 17. Routing  To navigate between multiple pages but make application work as single page application routing is used.  Since html page can not embed another html page in it routing in ANGULARJS provides such functionality.  To make routing work the angular app must run on server  So to run angular app in server  Install xampp  Create angular app  Add angular-route.js file to your application to enable routing.  Add your app inside xampp/htdocs  Run the application
  • 18. Routing example :  create index.html  Add angular-route.js in the script  Main, City 1, City 2 to navigate between all three pages called by them <body ng-app="myApp"> <p><a href="#/!">Main</a></p> <a href="#!london">City 1</a> <a href="#!paris">City 2</a>
  • 19. <script> var app = angular.module("myApp", ["ngRoute"]); app.config(function($routeProvider) { $routeProvider .when("/", { templateUrl : "main.htm“  redirects to main.htm when nothing is clicked }) .when("/london", { templateUrl : "london.htm“  redirects to london.htm when City 1 is clicked }) .when("/paris", { templateUrl : "paris.htm“  redirects to paris.htm when City 2 is clicked }); }); </script>