SlideShare a Scribd company logo
AngularJS
AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your
template language and lets you extend HTML's syntax to express your application's
components clearly and succinctly. Angular's data binding and dependency injection
eliminate much of the code you would otherwise have to write. And it all happens within the
browser, making it an ideal partner with any server technology.
AngularJS is a JavaScript framework. It is a library written in JavaScript.
AngularJS is distributed as a JavaScript file, and can be added to a web page with a script
tag:
AngularJS is a JavaScript framework for organizing HTML code in a more structural. This
client-side technology provides easy and light code in order to make developing and even
designing as a simple task.
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></scrip
t>
AngularJS Extends:
The ng-app directive defines an AngularJS application.
The ng-model directive binds the value of HTML controls (input, select, textarea) to
application data.
The ng-bind directive binds application data to the HTML view.
Sample Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="">
<p>Name:
<asp:TextBox ID="txtname" runat="server" ng-model="name">
</asp:TextBox>
</p>
<p ng-bind="name"></p>
</div>
</form>
</body>
</html>
AngularJS starts automatically when the web page has loaded.
The ng-init directive initialize AngularJS application variables.
ng-init Example:
<div ng-app="" ng-init="firstName='Prasad'">
<p>The name is <span ng-bind="firstName"></span></p>
</div>
AngularJS Expressions:
1) AngularJS expressions are written inside double braces: {{ expression }}.
2) AngularJS expressions binds data to HTML the same way as the ng-bind directive.
3) AngularJS will "output" data exactly where the expression is written.
Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<div ng-app="">
<p>My first expression: {{ 5 + 5 }}</p>
</div>
</div>
</form>
</body>
</html>
AngularJS Numbers: AngularJS numbers are like JavaScript numbers:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="" ng-init="quantity=1;price=5">
Quantity:
<asp:TextBox ID="txtquality" runat="server" type="number" ng-
model="quantity"></asp:TextBox>
Costs:
<asp:TextBox ID="txtprice" runat="server" type="number" ng-
model="price"></asp:TextBox>
Total in dollar: {{ quantity * price }}
</div>
</form>
</body>
</html>
AngularJS Strings: AngularJS strings are like JavaScript strings:
Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="" ng-init="firstName='Prasad';lastName='D'">
<p>The name is {{ firstName + " " + lastName }}</p>
OR
<p>The name is <span ng-bind="firstName + ' ' + lastName"></span></p>
</div>
</form>
</body>
</html>
AngularJS Objects: AngularJS objects are like JavaScript objects:
Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1”>
<div ng-app="" ng-init="person={firstName:'Prasad',lastName:'D'}">
<p>The name is {{ person.lastName }}</p>
</div>
</form>
</body>
</html>
AngularJS Arrays: AngularJS arrays are like JavaScript arrays:
Var obj=[2,4,6];
Example:
<!DOCTYPE html>
<html">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="" ng-init="numbers= [1,3,5,6,8]">
<p>The third result is: {{points[3]}}</p>
<p>The third result is <span ng-bind="numbers [2]"></span></p>
</div>
</form>
</body>
</html>
AngularJS Directives:
1) The ng-app directive initializes an AngularJS application.
2) The ng-init directive initializes application data.
3) The ng-model directive binds the value of HTML controls to application data.
Example:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="" ng-init="firstName='Prasad';lastName='D'">
<p>The name is {{ firstName + " " + lastName }}</p>
</div>
</form>
</body>
</html>
Repeating HTML Elements: The ng-repeat directive repeats an HTML element:
Example: display multiple rows and columns data using looping.
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div ng-app="" ng-init=" names=[{name:'Jani',country:'Norway'},
{name:'Hege',country:'Sweden'},
{name:'Kai',country:'Denmark'}]">
<ul>
<li ng-repeat="y in names">{{ y.name + ', ' + y.country }}
</li>
</ul>
</div>
</form>
</body>
</html>
AngularJS Controllers:
A controller is a JavaScript Object, created by a standard JavaScript object
constructor. AngularJS applications are controlled by controllers. The ng-
controller directive defines the application controller.
Example:
<!DOCTYPE html>
<html">
<head>
<title></title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
</head>
<body>
<form id="form1">
<div ng-app="myApp" ng-controller="myCtrl">
First Name: <asp:TextBox ID="txtfname" runat="server"
ng-model="firstName"></asp:TextBox><br>
Last Name: <asp:TextBox ID="txtlname" runat="server"
ng-model="lastName"></asp:TextBox><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "Prasad";
$scope.lastName = "D";
});
</script>
</form>
</body>
</html>
Controller Methods: A controller can also have methods (variables as functions):
<div ng-app="myApp" ng-controller="personCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{fullName()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe";
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
}
});
</script>
AngularJS Filters: AngularJS filters can be used to transform data:
Filter Description
Currency Format a number to a currency format
Filter Select a subset of items from an array.
Lowercase Format a string to lowercase.
Uppercase Format a string to uppercase.
orderBy Order an array by an expression.
Adding Filters to Expressions
A filter can be added to an expression with a pipe character (|) and a filter.
The uppercase filter format strings to upper case:
The lowercase filter format strings to lower case:
Example: uppercase-lowercase.html
The currency Filter :
The currency filter formats a number as currency:
Example : currency-filter.html
Filters to Directives
A filter can be added to a directive with a pipe character (|) and a filter.
The orderBy filter orders an array by an expression:
Example : filter-directives.html
Filtering Input : An input filter can be added to a directive with a pipe character (|) and
filter followed by a colon and a model name.
The filter filter selects a subset of an array:
Example: filter-input.html
AngularJS AJAX - $http :
AngularJS $http is a core service for reading data from web servers.
$http.get(url) is the function to use for reading server data.
Example : angularjs-http-get.html
The AngularJS application is defined by ng-app. The application runs inside a <div>.
The ng-controller directive names the controller object.
The customersCtrl function is a standard JavaScript object constructor.
AngularJS will invoke customersCtrl with a $scope and $http object.
$scope is the application object (the owner of application variables and functions).
$http is an XMLHttpRequest object for requesting external data.
$http.get() reads JSON data from http://www.w3schools.com/angular/customers.php.
If success, the controller creates a property (names) in the scope, with JSON data from
the server.
Displaying Data in a Table :
We can display data in table format using ng-repeat directive. It is perfect for displaying
tables.
Example: angularjs-tables.html
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
Displaying with CSS Style
To make it nice, add some CSS to the page:
Example : angularjs-tables.html
Display with orderBy Filter
To sort the table, add an orderBy filter:
Example :
<table>
<tr ng-repeat="x in names | orderBy : 'Country'">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
Display with uppercase Filter :
To display uppercase, add an uppercase filter:
Example:
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Country | uppercase }}</td>
</tr>
</table>
Table Index ($index): To display the table index, add a <td> with $index:
Example:
<table>
<tr ng-repeat="x in names">
<td>{{ $index + 1 }}</td>
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
AngularJS Example Application with SqlServer
AngularJS HTML DOM : The ng-disabled directive binds AngularJS application data to the
disabled attribute of HTML elements.
Example : angularjs-disabled.html
<div ng-app="">
<p>
<button ng-disabled="mySwitch">Click Me!</button>
</p><p>
<input type="checkbox" ng-model="mySwitch">Button
</p>
</div>
The ng-disabled directive binds the application data mySwitch to the HTML
button's disabled attribute.
The ng-model directive binds the value of the HTML checkbox element to the value
of mySwitch.
If the value of mySwitch evaluates to true, the button will be disabled:
The ng-show Directive
The ng-show directive shows or hides an HTML element.
Example: angularjs-ng-show.html
<div ng-app="">
<p ng-show="true">I am visible.</p>
<p ng-show="false">I am not visible.</p>
</div>
The ng-show directive shows (or hides) an HTML element based on the value of ng-show.
You can use any expression that evaluates to true or false:
AngularJS Events :
The ng-click Directive :
The ng-click directive defines an AngularJS click event.
Example : angularjs-ng-click.html
<div ng-app="" ng-controller="myCtrl">
<button ng-click="count = count + 1">Click me!</button>
<p>{{ count }}</p>
</div>
Hiding HTML Elements :
The ng-hide directive can be used to set the visibility of a part of an application.
The value ng-hide="true" makes an HTML element invisible.
The value ng-hide="false" makes the element visible.
Example : angularjs-ng-hide.html
The first part of the personController is the same as in the chapter about controllers.
The application has a default property (a variable): $scope.myVar = false;
The ng-hide directive sets the visibility, of a <p> element with two input fields,
according to the value (true or false) of myVar.
The function toggle() toggles myVar between true and false.
The value ng-hide="true" makes the element invisible.
Showing HTML Elements :
The ng-show directive can also be used to set the visibility of a part of an application.
The value ng-show="false" makes an HTML element invisible.
The value ng-show="true" makes the element visible.
Here is the same example as above, using ng-show instead of ng-hide:
Example: angularjs-ng-show.html
<div ng-app="myApp" ng-controller="personCtrl">
<button ng-click="toggle()">Toggle</button>
<p ng-show="myVar">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</p>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('personCtrl', function($scope) {
$scope.firstName = "Harish",
$scope.lastName = "G"
$scope.myVar = true;
$scope.toggle = function() {
$scope.myVar = !$scope.myVar;
}
});
</script>
AngularJS Modules :
An AngularJS module defines an application.
A module is a container for the different parts of an application.
All application controllers should belong to a module.
A Module With One Controller
This application ("myApp"), has one controller ("myCtrl"):
Example: modules examples
Modules and Controllers in Files :
It is common in AngularJS applications to put the module and the controllers in JavaScript
files. In this example, "myApp.js" contains an application module definition, while
"myCtrl.js" contains the controller:
Forms in AngularJS :
An AngularJS form is a collection of input controls.
HTML Controls
HTML input elements are called HTML controls:
 input elements
 select elements
 button elements
 textarea elements
Example : angularjs-forms.html
The ng-app directive defines the AngularJS application.
The ng-controller directive defines the application controller.
The ng-model directive binds two input elements to the user object in the model.
The formCtrl function sets initial values to the master object, and defines
the reset() method.
The reset() method sets the user object equal to the master object.
The ng-click directive invokes the reset() method, only if the button is clicked.
AngularJS Input Validation : AngularJS forms and controls can provide validation
services, and notify users of invalid input.
Example: angularjs-validations.html
AngularJS API : API stands for Application Programming Interface.
AngularJS Global API :
The AngularJS Global API is a set of global JavaScript functions for performing common
tasks like:
 Comparing objects
 Iterating objects
 Converting data
The Global API functions are accessed using the angular object.
API Description
Angular.lowecase() Converts a string to lowercase.
Angular.uppercase() Converts a string to uppercase.
Angular.isString() Returns true if the reference is a string.
Angular.isNumber() Returns true if the reference is a number.
Service and factory, custom directory, templates
Custome Directives : Custom directives are used in AngularJS to extend the functionality
of HTML. Custom directives are defined using "directive" function. A custom directive simply
replaces the element for which it is activated. AngularJS provides support to create custom
directives for following type of elements.
 Element directives - Directive activates when a matching element is encountered.
 Attribute - - Directive activates when a matching attribute is encountered.
 CSS - - Directive activates when a matching css style is encountered.
 Comment - - Directive activates when a matching comment is encountered.
Example : angularjs-custom-directives.html
Services & Factory :
Factory : A factory is a simple function which allows you to add some logic before creating
object. It returns the created object.
Syntax: app.factory(‘servicename’,function(){return serviceObj;})
Example :
module.factory('userService', function(){
var fac = {};
fac.users = ['John', 'James', 'Jake'];
return fac;
});
Services : A service is a construction function which creates the object using new keyword.
You can add properties and functions to a service object by using this keyword.
Example : services-example.html
AngularJS Templates: In Angular, templates are the views with the HTML enriched by
Angular elements like directive and attributes. Templates are used to display the
information from the model and controller that a user sees in his browser.
There are 2 types of templates :
1) Static Templates : A static template is defined by using script tag. It must has an id attribute
with a unique value and a type attribute with value text/ng-template. Also, a static template
must be inside the scope of the ng-app directive otherwise it will be ignored by Angular.
Example : static-templates.html
2) Dynamic Templates : A dynamic template is an html page which is compiled and rendered by
Angular on demand.
Example : dynamic-templates.html
$watch()
The $scope.watch() function creates a watch of some variable. When you register a
watch you pass two functions as parameters to the $watch() function:
 A value function
 A listener function
$scope.$watch(function() {},
function() {}
);
The first function is the value function and the second function is the listener function.
The value function should return the value which is being watched. AngularJS can then check
the value returned against the value the watch function returned the last time. That way
AngularJS can determine if the value has changed. Here is an example:
$scope.$watch(function(scope) { return scope.data.myVar },
function() {}
);
http://www.dotnet-tricks.com/Tutorial/angularjs/V2YS090914-Understanding-
AngularJS-Factory,-Service-and-Provider.html
What is AngularJS?
Ans: AngularJS is a javascript framework used for creating single web page
applications. It simplifies binding javascript objects with HTML ui elements. It allows
you to use html as your template language and enables you to extend HTML’s syntax to
express your application’s components clearly.
What are key the features of Angularjs?
Ans: Model, View, Controller, Directives, Filters, Scope, Services, Data Binding.
What is a directive in AngularJS and what are different types of directives?
Ans: Directives are attributes decorated on the HTML elements. All directives start with
the word “ng”. As the name says directive it directs angular what to do.
During compilation process when special HTML constructs are encountered a function is
triggered, this function is referred as directive. It is executed when the compiler
encounters it in the DOM.
1) Element Directive
2) Attribute Directive
3) CSS class Directive
4) Comment Directive
What are the advantages of angularjs?
Ans:
1) AngularJS supports MVC pattern.
2) Using angularjs can do 2 ways binding.
3) It has pre-defined form validations.
4) It supports client-server communications.
5) It supports animations.
What is “$rootScope” and how is it related with “$scope”?
Ans: “$rootScope” is a parent object of all “$scope” angular objects created in a
webpage.
How is the data binding in angularjs?
Ans: its two way binding. So whenever you make changes in one entity the other entity
also gets updated.

More Related Content

What's hot (19)

PPTX
Understanding angular js
Aayush Shrestha
 
PDF
Html server control - ASP. NET with c#
priya Nithya
 
PPTX
Angular js
Behind D Walls
 
PPTX
Basics of AngularJS
Filip Janevski
 
PPT
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
PPTX
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
PPTX
AngularJS Best Practices
Narek Mamikonyan
 
PDF
jQuery and Rails: Best Friends Forever
stephskardal
 
PDF
AngularJS: an introduction
Luigi De Russis
 
PPTX
Why Django for Web Development
Morteza Zohoori Shoar
 
PPT
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
PPT
jQuery and AJAX with Rails
Alan Hecht
 
PPTX
Angular JS - Introduction
Sagar Acharya
 
PPTX
The Django Web Application Framework 2
fishwarter
 
PPTX
Angular js
Dinusha Nandika
 
PPT
jQuery Ajax
Anand Kumar Rajana
 
KEY
Html 5, a gentle introduction
Diego Scataglini
 
PDF
Advanced Tips & Tricks for using Angular JS
Simon Guest
 
Understanding angular js
Aayush Shrestha
 
Html server control - ASP. NET with c#
priya Nithya
 
Angular js
Behind D Walls
 
Basics of AngularJS
Filip Janevski
 
AngularJS Mobile Warsaw 20-10-2014
Dariusz Kalbarczyk
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
murtazahaveliwala
 
AngularJS Best Practices
Narek Mamikonyan
 
jQuery and Rails: Best Friends Forever
stephskardal
 
AngularJS: an introduction
Luigi De Russis
 
Why Django for Web Development
Morteza Zohoori Shoar
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Apaichon Punopas
 
jQuery and AJAX with Rails
Alan Hecht
 
Angular JS - Introduction
Sagar Acharya
 
The Django Web Application Framework 2
fishwarter
 
Angular js
Dinusha Nandika
 
jQuery Ajax
Anand Kumar Rajana
 
Html 5, a gentle introduction
Diego Scataglini
 
Advanced Tips & Tricks for using Angular JS
Simon Guest
 

Viewers also liked (20)

PDF
Angularjs interview questions and answers
prasaddammalapati
 
PDF
RESTful API development in Laravel 4 - Christopher Pecoraro
Christopher Pecoraro
 
PDF
Laravel Restful API and AngularJS
Blake Newman
 
PDF
Laravel Blade
Julien TANT
 
PDF
Web services with laravel
Confiz
 
PDF
Thinking beyond RDBMS - Building Polyglot Persistence Java Applications Devf...
Shekhar Gulati
 
PDF
Introduction to Browser DOM
Siva Arunachalam
 
PDF
Open shift for java(ee) developers
Shekhar Gulati
 
PPTX
Design Patterns for JavaScript Web Apps - JavaScript Conference 2012 - OPITZ ...
OPITZ CONSULTING Deutschland
 
PPTX
AngularJS & Job
ganesgo
 
PDF
Surviving as a Professional Software Developer
Yakov Fain
 
PDF
Java EE 6 and NoSQL Workshop DevFest Austria
Shekhar Gulati
 
PDF
Bringing spatial love to your python application
Shekhar Gulati
 
PDF
Developing modern java web applications with java ee 7 and angular js
Shekhar Gulati
 
PDF
Hicss 42 Presentation
Barbara Ondrisek
 
ODP
Simple Mobile Development With Ionic - Ondrisek
Barbara Ondrisek
 
PPT
Indic threads java10-spring-roo-and-the-cloud
Shekhar Gulati
 
PDF
Becoming a professional software developer
Yakov Fain
 
PDF
Interacting with the DOM (JavaScript)
Florence Davis
 
PDF
Working effectively with OpenShift
Shekhar Gulati
 
Angularjs interview questions and answers
prasaddammalapati
 
RESTful API development in Laravel 4 - Christopher Pecoraro
Christopher Pecoraro
 
Laravel Restful API and AngularJS
Blake Newman
 
Laravel Blade
Julien TANT
 
Web services with laravel
Confiz
 
Thinking beyond RDBMS - Building Polyglot Persistence Java Applications Devf...
Shekhar Gulati
 
Introduction to Browser DOM
Siva Arunachalam
 
Open shift for java(ee) developers
Shekhar Gulati
 
Design Patterns for JavaScript Web Apps - JavaScript Conference 2012 - OPITZ ...
OPITZ CONSULTING Deutschland
 
AngularJS & Job
ganesgo
 
Surviving as a Professional Software Developer
Yakov Fain
 
Java EE 6 and NoSQL Workshop DevFest Austria
Shekhar Gulati
 
Bringing spatial love to your python application
Shekhar Gulati
 
Developing modern java web applications with java ee 7 and angular js
Shekhar Gulati
 
Hicss 42 Presentation
Barbara Ondrisek
 
Simple Mobile Development With Ionic - Ondrisek
Barbara Ondrisek
 
Indic threads java10-spring-roo-and-the-cloud
Shekhar Gulati
 
Becoming a professional software developer
Yakov Fain
 
Interacting with the DOM (JavaScript)
Florence Davis
 
Working effectively with OpenShift
Shekhar Gulati
 
Ad

Similar to Angular js (20)

PPTX
Angular js
Steve Fort
 
PPTX
Angular js
ParmarAnisha
 
PDF
Dive into AngularJS and directives
Tricode (part of Dept)
 
PPTX
Angular Javascript Tutorial with command
ssuser42b933
 
PDF
Workshop 12: AngularJS Parte I
Visual Engineering
 
PPTX
AngularJs
syam kumar kk
 
PPTX
The Basics Angular JS
OrisysIndia
 
PPTX
Angular directive filter and routing
jagriti srivastava
 
PDF
Introduction to angular js july 6th 2014
Simona Clapan
 
PPTX
Custom directive and scopes
jagriti srivastava
 
DOCX
Controller in AngularJS
Brajesh Yadav
 
PPTX
intro to Angular js
Brian Atkins
 
PPTX
Starting with angular js
jagriti srivastava
 
PPTX
AngularJS Introduction, how to run Angular
SamuelJohnpeter
 
PDF
Create an application with ember
Chandra Sekar
 
PDF
AngularJS By Vipin
Vipin Mundayad
 
PPT
JS-05-Handlebars.ppt
fakeaccount225095
 
PDF
Working with Javascript in Rails
Seungkyun Nam
 
PPT
ASP.NET MVC introduction
Tomi Juhola
 
Angular js
Steve Fort
 
Angular js
ParmarAnisha
 
Dive into AngularJS and directives
Tricode (part of Dept)
 
Angular Javascript Tutorial with command
ssuser42b933
 
Workshop 12: AngularJS Parte I
Visual Engineering
 
AngularJs
syam kumar kk
 
The Basics Angular JS
OrisysIndia
 
Angular directive filter and routing
jagriti srivastava
 
Introduction to angular js july 6th 2014
Simona Clapan
 
Custom directive and scopes
jagriti srivastava
 
Controller in AngularJS
Brajesh Yadav
 
intro to Angular js
Brian Atkins
 
Starting with angular js
jagriti srivastava
 
AngularJS Introduction, how to run Angular
SamuelJohnpeter
 
Create an application with ember
Chandra Sekar
 
AngularJS By Vipin
Vipin Mundayad
 
JS-05-Handlebars.ppt
fakeaccount225095
 
Working with Javascript in Rails
Seungkyun Nam
 
ASP.NET MVC introduction
Tomi Juhola
 
Ad

Recently uploaded (20)

PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PPTX
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
PPTX
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
PDF
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
PDF
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
PDF
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PDF
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
PDF
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
PDF
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
PPTX
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
PPTX
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
PPTX
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Milwaukee Marketo User Group - Summer Road Trip: Mapping and Personalizing Yo...
bbedford2
 
Empowering Asian Contributions: The Rise of Regional User Groups in Open Sour...
Shane Coughlan
 
TheFutureIsDynamic-BoxLang witch Luis Majano.pdf
Ortus Solutions, Corp
 
MiniTool Partition Wizard Free Crack + Full Free Download 2025
bashirkhan333g
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
In From the Cold: Open Source as Part of Mainstream Software Asset Management
Shane Coughlan
 
Top Agile Project Management Tools for Teams in 2025
Orangescrum
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Automate Cybersecurity Tasks with Python
VICTOR MAESTRE RAMIREZ
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Driver Easy Pro 6.1.1 Crack Licensce key 2025 FREE
utfefguu
 
Wondershare PDFelement Pro Crack for MacOS New Version Latest 2025
bashirkhan333g
 
MiniTool Partition Wizard 12.8 Crack License Key LATEST
hashhshs786
 
Help for Correlations in IBM SPSS Statistics.pptx
Version 1 Analytics
 
Finding Your License Details in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Download Canva Pro 2025 PC Crack Full Latest Version
bashirkhan333g
 
OpenChain @ OSS NA - In From the Cold: Open Source as Part of Mainstream Soft...
Shane Coughlan
 

Angular js

  • 1. AngularJS AngularJS is a structural framework for dynamic web apps. It lets you use HTML as your template language and lets you extend HTML's syntax to express your application's components clearly and succinctly. Angular's data binding and dependency injection eliminate much of the code you would otherwise have to write. And it all happens within the browser, making it an ideal partner with any server technology. AngularJS is a JavaScript framework. It is a library written in JavaScript. AngularJS is distributed as a JavaScript file, and can be added to a web page with a script tag: AngularJS is a JavaScript framework for organizing HTML code in a more structural. This client-side technology provides easy and light code in order to make developing and even designing as a simple task. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></scrip t> AngularJS Extends: The ng-app directive defines an AngularJS application. The ng-model directive binds the value of HTML controls (input, select, textarea) to application data. The ng-bind directive binds application data to the HTML view. Sample Example: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app=""> <p>Name: <asp:TextBox ID="txtname" runat="server" ng-model="name"> </asp:TextBox> </p> <p ng-bind="name"></p> </div> </form> </body> </html> AngularJS starts automatically when the web page has loaded. The ng-init directive initialize AngularJS application variables. ng-init Example:
  • 2. <div ng-app="" ng-init="firstName='Prasad'"> <p>The name is <span ng-bind="firstName"></span></p> </div> AngularJS Expressions: 1) AngularJS expressions are written inside double braces: {{ expression }}. 2) AngularJS expressions binds data to HTML the same way as the ng-bind directive. 3) AngularJS will "output" data exactly where the expression is written. Example: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div> <div ng-app=""> <p>My first expression: {{ 5 + 5 }}</p> </div> </div> </form> </body> </html> AngularJS Numbers: AngularJS numbers are like JavaScript numbers: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app="" ng-init="quantity=1;price=5"> Quantity: <asp:TextBox ID="txtquality" runat="server" type="number" ng- model="quantity"></asp:TextBox> Costs: <asp:TextBox ID="txtprice" runat="server" type="number" ng- model="price"></asp:TextBox> Total in dollar: {{ quantity * price }} </div> </form>
  • 3. </body> </html> AngularJS Strings: AngularJS strings are like JavaScript strings: Example: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app="" ng-init="firstName='Prasad';lastName='D'"> <p>The name is {{ firstName + " " + lastName }}</p> OR <p>The name is <span ng-bind="firstName + ' ' + lastName"></span></p> </div> </form> </body> </html> AngularJS Objects: AngularJS objects are like JavaScript objects: Example: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1”> <div ng-app="" ng-init="person={firstName:'Prasad',lastName:'D'}"> <p>The name is {{ person.lastName }}</p> </div> </form> </body> </html> AngularJS Arrays: AngularJS arrays are like JavaScript arrays: Var obj=[2,4,6]; Example: <!DOCTYPE html> <html"> <head runat="server"> <title></title>
  • 4. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app="" ng-init="numbers= [1,3,5,6,8]"> <p>The third result is: {{points[3]}}</p> <p>The third result is <span ng-bind="numbers [2]"></span></p> </div> </form> </body> </html> AngularJS Directives: 1) The ng-app directive initializes an AngularJS application. 2) The ng-init directive initializes application data. 3) The ng-model directive binds the value of HTML controls to application data. Example: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app="" ng-init="firstName='Prasad';lastName='D'"> <p>The name is {{ firstName + " " + lastName }}</p> </div> </form> </body> </html> Repeating HTML Elements: The ng-repeat directive repeats an HTML element: Example: display multiple rows and columns data using looping. <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1" runat="server"> <div ng-app="" ng-init=" names=[{name:'Jani',country:'Norway'}, {name:'Hege',country:'Sweden'},
  • 5. {name:'Kai',country:'Denmark'}]"> <ul> <li ng-repeat="y in names">{{ y.name + ', ' + y.country }} </li> </ul> </div> </form> </body> </html> AngularJS Controllers: A controller is a JavaScript Object, created by a standard JavaScript object constructor. AngularJS applications are controlled by controllers. The ng- controller directive defines the application controller. Example: <!DOCTYPE html> <html"> <head> <title></title> <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <form id="form1"> <div ng-app="myApp" ng-controller="myCtrl"> First Name: <asp:TextBox ID="txtfname" runat="server" ng-model="firstName"></asp:TextBox><br> Last Name: <asp:TextBox ID="txtlname" runat="server" ng-model="lastName"></asp:TextBox><br> <br> Full Name: {{firstName + " " + lastName}} </div> <script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope) { $scope.firstName = "Prasad"; $scope.lastName = "D"; }); </script> </form> </body> </html> Controller Methods: A controller can also have methods (variables as functions): <div ng-app="myApp" ng-controller="personCtrl"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{fullName()}}
  • 6. </div> <script> var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.firstName = "John"; $scope.lastName = "Doe"; $scope.fullName = function() { return $scope.firstName + " " + $scope.lastName; } }); </script> AngularJS Filters: AngularJS filters can be used to transform data: Filter Description Currency Format a number to a currency format Filter Select a subset of items from an array. Lowercase Format a string to lowercase. Uppercase Format a string to uppercase. orderBy Order an array by an expression. Adding Filters to Expressions A filter can be added to an expression with a pipe character (|) and a filter. The uppercase filter format strings to upper case: The lowercase filter format strings to lower case: Example: uppercase-lowercase.html The currency Filter : The currency filter formats a number as currency: Example : currency-filter.html Filters to Directives A filter can be added to a directive with a pipe character (|) and a filter. The orderBy filter orders an array by an expression: Example : filter-directives.html Filtering Input : An input filter can be added to a directive with a pipe character (|) and filter followed by a colon and a model name. The filter filter selects a subset of an array: Example: filter-input.html AngularJS AJAX - $http : AngularJS $http is a core service for reading data from web servers. $http.get(url) is the function to use for reading server data. Example : angularjs-http-get.html
  • 7. The AngularJS application is defined by ng-app. The application runs inside a <div>. The ng-controller directive names the controller object. The customersCtrl function is a standard JavaScript object constructor. AngularJS will invoke customersCtrl with a $scope and $http object. $scope is the application object (the owner of application variables and functions). $http is an XMLHttpRequest object for requesting external data. $http.get() reads JSON data from http://www.w3schools.com/angular/customers.php. If success, the controller creates a property (names) in the scope, with JSON data from the server. Displaying Data in a Table : We can display data in table format using ng-repeat directive. It is perfect for displaying tables. Example: angularjs-tables.html <table> <tr ng-repeat="x in names"> <td>{{ x.Name }}</td> <td>{{ x.Country }}</td> </tr> </table> Displaying with CSS Style To make it nice, add some CSS to the page: Example : angularjs-tables.html Display with orderBy Filter To sort the table, add an orderBy filter: Example : <table> <tr ng-repeat="x in names | orderBy : 'Country'"> <td>{{ x.Name }}</td> <td>{{ x.Country }}</td> </tr> </table> Display with uppercase Filter : To display uppercase, add an uppercase filter: Example: <table> <tr ng-repeat="x in names"> <td>{{ x.Name }}</td> <td>{{ x.Country | uppercase }}</td> </tr> </table> Table Index ($index): To display the table index, add a <td> with $index: Example:
  • 8. <table> <tr ng-repeat="x in names"> <td>{{ $index + 1 }}</td> <td>{{ x.Name }}</td> <td>{{ x.Country }}</td> </tr> </table> AngularJS Example Application with SqlServer AngularJS HTML DOM : The ng-disabled directive binds AngularJS application data to the disabled attribute of HTML elements. Example : angularjs-disabled.html <div ng-app=""> <p> <button ng-disabled="mySwitch">Click Me!</button> </p><p> <input type="checkbox" ng-model="mySwitch">Button </p> </div> The ng-disabled directive binds the application data mySwitch to the HTML button's disabled attribute. The ng-model directive binds the value of the HTML checkbox element to the value of mySwitch. If the value of mySwitch evaluates to true, the button will be disabled: The ng-show Directive The ng-show directive shows or hides an HTML element. Example: angularjs-ng-show.html <div ng-app=""> <p ng-show="true">I am visible.</p> <p ng-show="false">I am not visible.</p> </div> The ng-show directive shows (or hides) an HTML element based on the value of ng-show. You can use any expression that evaluates to true or false: AngularJS Events : The ng-click Directive : The ng-click directive defines an AngularJS click event. Example : angularjs-ng-click.html <div ng-app="" ng-controller="myCtrl"> <button ng-click="count = count + 1">Click me!</button>
  • 9. <p>{{ count }}</p> </div> Hiding HTML Elements : The ng-hide directive can be used to set the visibility of a part of an application. The value ng-hide="true" makes an HTML element invisible. The value ng-hide="false" makes the element visible. Example : angularjs-ng-hide.html The first part of the personController is the same as in the chapter about controllers. The application has a default property (a variable): $scope.myVar = false; The ng-hide directive sets the visibility, of a <p> element with two input fields, according to the value (true or false) of myVar. The function toggle() toggles myVar between true and false. The value ng-hide="true" makes the element invisible. Showing HTML Elements : The ng-show directive can also be used to set the visibility of a part of an application. The value ng-show="false" makes an HTML element invisible. The value ng-show="true" makes the element visible. Here is the same example as above, using ng-show instead of ng-hide: Example: angularjs-ng-show.html <div ng-app="myApp" ng-controller="personCtrl"> <button ng-click="toggle()">Toggle</button> <p ng-show="myVar"> First Name: <input type="text" ng-model="firstName"><br> Last Name: <input type="text" ng-model="lastName"><br> <br> Full Name: {{firstName + " " + lastName}} </p> </div> <script> var app = angular.module('myApp', []); app.controller('personCtrl', function($scope) { $scope.firstName = "Harish", $scope.lastName = "G" $scope.myVar = true; $scope.toggle = function() { $scope.myVar = !$scope.myVar; } }); </script> AngularJS Modules : An AngularJS module defines an application. A module is a container for the different parts of an application. All application controllers should belong to a module.
  • 10. A Module With One Controller This application ("myApp"), has one controller ("myCtrl"): Example: modules examples Modules and Controllers in Files : It is common in AngularJS applications to put the module and the controllers in JavaScript files. In this example, "myApp.js" contains an application module definition, while "myCtrl.js" contains the controller: Forms in AngularJS : An AngularJS form is a collection of input controls. HTML Controls HTML input elements are called HTML controls:  input elements  select elements  button elements  textarea elements Example : angularjs-forms.html The ng-app directive defines the AngularJS application. The ng-controller directive defines the application controller. The ng-model directive binds two input elements to the user object in the model. The formCtrl function sets initial values to the master object, and defines the reset() method. The reset() method sets the user object equal to the master object. The ng-click directive invokes the reset() method, only if the button is clicked. AngularJS Input Validation : AngularJS forms and controls can provide validation services, and notify users of invalid input. Example: angularjs-validations.html AngularJS API : API stands for Application Programming Interface. AngularJS Global API : The AngularJS Global API is a set of global JavaScript functions for performing common tasks like:  Comparing objects  Iterating objects  Converting data The Global API functions are accessed using the angular object. API Description Angular.lowecase() Converts a string to lowercase.
  • 11. Angular.uppercase() Converts a string to uppercase. Angular.isString() Returns true if the reference is a string. Angular.isNumber() Returns true if the reference is a number. Service and factory, custom directory, templates Custome Directives : Custom directives are used in AngularJS to extend the functionality of HTML. Custom directives are defined using "directive" function. A custom directive simply replaces the element for which it is activated. AngularJS provides support to create custom directives for following type of elements.  Element directives - Directive activates when a matching element is encountered.  Attribute - - Directive activates when a matching attribute is encountered.  CSS - - Directive activates when a matching css style is encountered.  Comment - - Directive activates when a matching comment is encountered. Example : angularjs-custom-directives.html Services & Factory : Factory : A factory is a simple function which allows you to add some logic before creating object. It returns the created object. Syntax: app.factory(‘servicename’,function(){return serviceObj;}) Example : module.factory('userService', function(){ var fac = {}; fac.users = ['John', 'James', 'Jake']; return fac; }); Services : A service is a construction function which creates the object using new keyword. You can add properties and functions to a service object by using this keyword. Example : services-example.html AngularJS Templates: In Angular, templates are the views with the HTML enriched by Angular elements like directive and attributes. Templates are used to display the information from the model and controller that a user sees in his browser. There are 2 types of templates : 1) Static Templates : A static template is defined by using script tag. It must has an id attribute with a unique value and a type attribute with value text/ng-template. Also, a static template must be inside the scope of the ng-app directive otherwise it will be ignored by Angular. Example : static-templates.html
  • 12. 2) Dynamic Templates : A dynamic template is an html page which is compiled and rendered by Angular on demand. Example : dynamic-templates.html $watch() The $scope.watch() function creates a watch of some variable. When you register a watch you pass two functions as parameters to the $watch() function:  A value function  A listener function $scope.$watch(function() {}, function() {} ); The first function is the value function and the second function is the listener function. The value function should return the value which is being watched. AngularJS can then check the value returned against the value the watch function returned the last time. That way AngularJS can determine if the value has changed. Here is an example: $scope.$watch(function(scope) { return scope.data.myVar }, function() {} ); http://www.dotnet-tricks.com/Tutorial/angularjs/V2YS090914-Understanding- AngularJS-Factory,-Service-and-Provider.html
  • 13. What is AngularJS? Ans: AngularJS is a javascript framework used for creating single web page applications. It simplifies binding javascript objects with HTML ui elements. It allows you to use html as your template language and enables you to extend HTML’s syntax to express your application’s components clearly. What are key the features of Angularjs? Ans: Model, View, Controller, Directives, Filters, Scope, Services, Data Binding. What is a directive in AngularJS and what are different types of directives? Ans: Directives are attributes decorated on the HTML elements. All directives start with the word “ng”. As the name says directive it directs angular what to do. During compilation process when special HTML constructs are encountered a function is triggered, this function is referred as directive. It is executed when the compiler encounters it in the DOM. 1) Element Directive 2) Attribute Directive 3) CSS class Directive 4) Comment Directive What are the advantages of angularjs? Ans: 1) AngularJS supports MVC pattern. 2) Using angularjs can do 2 ways binding. 3) It has pre-defined form validations. 4) It supports client-server communications. 5) It supports animations. What is “$rootScope” and how is it related with “$scope”? Ans: “$rootScope” is a parent object of all “$scope” angular objects created in a webpage. How is the data binding in angularjs? Ans: its two way binding. So whenever you make changes in one entity the other entity also gets updated.