Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 3: Introduction To Angularjs
Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 3: Introduction To Angularjs
Mrs. Sujata Oak Assistant Professor Department of It: Itc602-Web X.O Module 3: Introduction To Angularjs
O
Module 3 : Introduction to AngularJS
2 Module 5 : AngularJS
Module 4 : Introduction to AngularJS
THEORY
Module 5 : AngularJS
3
Module 4 : Introduction to AngularJS
Practical
4 Module 5 : AngularJS
Lecture 27
Introduction to AngularJS
Module 3 : AngularJS
7 Module 3 : AngularJS
Module 3 : Introduction to AngularJS
8 Module 3 : AngularJS
Module 3 : Introduction to AngularJS
It also helps you to reduce writing the code by data binding and
dependency injection.
https://www.madewithangular.com/
9 Module 3 : AngularJS
https://www.angularjswiki.com/angular/histor
y-of-angularjs/
Module 3 : History of AngularJS
Basics of Typescript.
11 Module 3 : AngularJS
Module 3 : Need of AngularJS
12 Module 3 : AngularJS
Module 3 : AngularJS Environment setup
13 Module 3 : AngularJS
Module 3 : AngularJS Environment setup
•CDN access − You also have access to a CDN. The CDN gives you
access to regional data centers. In this case, the Google host. The CDN
transfers the responsibility of hosting files from your own servers to a
series of external ones. It also offers an advantage that if the visitor of
your web page has already downloaded a copy of AngularJS from the
same CDN, there is no need to re-download it.
14 Module 3 : AngularJS
Module 3 : AngularJS Environment setup : CLI
15 Module 3 : AngularJS
Module 3 : AngularJS Environment setup : CLI
16 Module 3 : AngularJS
Module 3 : AngularJS MVC Architecture
Controller.
interface layer
17 Module 3 : AngularJS
Module 3 : AngularJS MVC Architecture
The Model:
•The model is responsible for managing application data. It responds to the
request from view and to the instructions from controller to update itself.
The View:
•A presentation of data in a particular format, triggered by the controller's
decision to present the data. They are script-based template systems such as
JSP, ASP, PHP and very easy to integrate with AJAX technology.
The Controller:
•The controller responds to user input and performs interactions on the data
model objects. The controller receives input, validates it, and then performs
business operations that modify the state of the data model.
20 Module 3 : AngularJS
Module 3 : Advantages
of AngularJS over other
JavaScript frameworks
• Dependency Injection: Dependency Injection specifies a design pattern in which
components are given their dependencies instead of hard coding them within
the component.
• Two way data binding: AngularJS creates a two way data-binding between the
select element and the orderProp model. orderProp is then used as the input
for the orderBy filter.
• Testing: Angular JS is designed in a way that we can test right from the start. So,
it is very easy to test any of its components through unit testing and end-to-end
testing.
22 Module 3 : AngularJS
Module 3 : AngularJS Directives
Directives are markers on a DOM element that tell
AngularJS to attach a specified behavior to that DOM
element or even transform the DOM element and its
children. In short, it extends the HTML.
23 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives
https://docs.angularjs.org/api/ng/directive
24 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-app
25 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-app
Demo:ngapp.html
26 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-init
Demo: nginit.html
27 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-model
28 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-model
29 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-model
Note :
30 Module 3 : AngularJS
Module 3 : Built-In AngularJS Directives : ng-bind
Demo: bind.html
31 Module 3 : AngularJS
Module 3 : AngularJS Expressions DEMO: ANGULAR->JS-
>index2.html
32 Module 3 : AngularJS
Module 3 : AngularJS Data binding
Data binding in AngularJS is the synchronization between the model
and the view components.
DEMO
34 Module 3 : AngularJS
AngularJS Data binding with
Module 3 :
styling
DEMO
databindstyle.html
databindselect.html
35 Module 3 : AngularJS
Module 3 : AngularJS ng-repeat
repeatdir.html
36 Module 3 : AngularJS
Module 3 : AngularJS Directives
37 Module 3 : AngularJS
Module 3 : AngularJS Module and Controller
38 Module 3 : AngularJS
Module 3 : AngularJS Module
A module in AngularJS is a container of the different parts of an
application such as controller, service, filters, directives etc.
Creating a Module
39 Module 3 : AngularJS
Module 3 : AngularJS Module
40 Module 3 : AngularJS
Module 3 : AngularJS Controller
41 Module 3 : AngularJS
Module 3 : AngularJS Controller
The controller in AngularJS is a JavaScript function that
maintains the application data and behavior using $scope
object.
Controller
43 Module 3 : AngularJS
AngularJS Modules and
Module 3 :
Controller
Here, module and controller are added in View using ng-App and
ng-controller directive of AngularJS.
44 Module 3 : AngularJS
Module 3 : AngularJS Controller Example
Name of the
controller
property of
studentContr
oller object
properties of
$scope.student object
45 Module 3 : AngularJS
Module 3 : AngularJS Custom Directives
46 Module 3 : AngularJS
Module 3 : AngularJS Custom Directives
custom.js
customdir.html
47 Module 3 : AngularJS
Module 3 : AngularJS Filters
{{expression | filterName:parameter }}
48 Module 3 : AngularJS
Module 3 : AngularJS Filters
49 Module 3 : AngularJS
Module 3 : AngularJS Filters
Uppercase/lowercase filter
The uppercase filter converts the string to upper case
and lowercase filter converts the string to lower case.
Ulfilter.html
50 Module 3 : AngularJS
Module 3 : AngularJS Filters
Filter
Filter.html
51 Module 3 : AngularJS
Module 3 : AngularJS Filters : OrderBy
52 Module 3 : AngularJS
Module 3 : AngularJS scope
The Scope is an object that is specified as a binding part between the
HTML (view) and the JavaScript (controller).
scope.html
53 Module 3 : AngularJS
Module 3 : AngularJS Root scope
• All applications have a $rootScope which is the scope created on the HTML
element that contains the ng-app directive.
• If a variable has the same name in both the current scope and in the rootScope,
the application uses the one in the current scope.
• The $rootScope is the top-most scope. An app can have only one $rootScope
which will be shared among all the components of an app. Hence it acts like a
global variable. All other $scopes are children of the $rootScope.
rootscope.html
54 Module 3 : AngularJS
Module 3 : AngularJS Dependency Injection
https://www.guru99.com/angularjs-dependency-injection.html
di.html
55 Module 3 : AngularJS
Module 3 : AngularJS Services
What is a Service?
•In AngularJS, a service is a function, or object, that is
available for your AngularJS application.
•AngularJS has about 30 built-in services.
56 Module 3 : AngularJS
Module 3 : AngularJS Services
$location Service :
servicelocation.html
57 Module 3 : AngularJS
Module 3 : AngularJS Services
The $http Service
httpservice.html
58 Module 3 : AngularJS
Module 3 : AngularJS Services
AngularJS includes a logging service called $log, which logs the messages to the client
browser's console.
The $log service includes different methods to handle the log for error, information,
warning or debug information. It can be useful in debugging and auditing.
The main purpose of all AngularJS logging services is to simplify debugging and
troubleshooting.
To reveal the location of the calls to $log in the JavaScript console; you can "blackbox"
the AngularJS source in your favorite browser. To blackbox in the browser, go to the
page, right click it, “Inspect” it in developer mode, and then read the console.
Some methods that we will use for logging in AngularJS $log are:
59 Module 3 : AngularJS
Module 3 : AngularJS $log Services
logservice.html
60 Module 3 : AngularJS
Module 3 : AngularJS Services
The $timeout Service
Timeoutser.html
61 Module 3 : AngularJS
Module 3 : AngularJS Form Validation
AngularJS can validate input data.
AngularJS monitors the state of the form and input fields (input,
textarea, select), and lets you notify the user about the current state.
You can use standard HTML5 attributes to validate input, or you can
62 Module 3 : AngularJS
Module 3 : AngularJS Form Validation
63 Module 3 : AngularJS
Module 3 : AngularJS Form Validation
64 Module 3 : AngularJS
Module 3 : Single-page application
the user by dynamically rewriting the current web page with new data from the web
server, instead of the default method of a web browser loading entire new pages.
The goal is faster transitions that make the website feel more like a native app.
and CSS code is either retrieved by the browser with a single page load, or the
appropriate resources are dynamically loaded and added to the page as necessary,
65 Module 3 : AngularJS
Module 3 : Single-page application
Single Page Applications (SPAs) are web applications that will works or loads on
a single HTML page and dynamically update the page based on user interaction.
That means, changing the content on what we want to route.
The SPA only sends what you need with each click, and your browser renders
that information. This is different than a traditional page load where the server
re-renders a full page with every click you make and sends it to your browser.
This client-side method makes load time much faster for users and makes the
amount of information a server has to send a lot less and a lot more cost
efficient.
66 Module 3 : AngularJS
Module 3 : AngularJS Routing
67 Module 3 : AngularJS
Module 3 : AngularJS Routing
68 Module 3 : AngularJS
Module 3 : AngularJS Routing
69 Module 3 : AngularJS
Module 3 : Where Does it goes
70 Module 3 : AngularJS
Module 3 : $routeProvider
templateUrl:"views/page1.html"
72 Module 3 : AngularJS
https://www.guru99.com/angularjs-views.html
Module 3 : ng-view
73 Module 3 : AngularJS
https://www.guru99.com/angularjs-views.html
Module 3 : ng-view
74 Module 3 : AngularJS
Module 3 : Angular ng-style Directive
75 Module 3 : AngularJS
Module 3 : Angular ng-style Directive
<body ng-app="myApp" ng-
controller="myCtrl">
Syntax :
<h1 ng-style="myObj">Welcome to ng-style
<element ng-
directive</h1>
style="expression"></
element>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "60px",
"padding" : "50px"
}
});
</script>
</body>
76 Module 3 : AngularJS
https://riptutorial.com/angularjs/topic/3032/built-in-helper-functions
77 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.copy
angular.copy()
Objects:
let obj = {name: "vespa", occupation: "princess"};
let cpy = angular.copy(obj);
cpy.name = "yogurt"
// obj = {name: "vespa", occupation: "princess"}
// cpy = {name: "yogurt", occupation: "princess"}
78 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.equals
The angular.equals function compares and determines if 2
objects or values are equal,
angular.equals performs a deep comparison and returns true
if and only if at least 1 of the following conditions is met.
angular.equals(value1, value2)
1.If the objects or values pass the === comparison
2.If both objects or values are of the same type, and all of their properties
are also equal by using angular.equals
3.Both values are equal to NaN
4.Both values represent the same regular expression's result.
79 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.equals
angular.equals(1, 1) // true
angular.equals(1, 2) // false
angular.equals({}, {}) // true,
note that {}==={} is false
angular.equals({a: 1}, {a: 1}) // true
angular.equals({a: 1}, {a: 2}) // false
angular.equals(NaN, NaN) // true
80 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.forEach
The angular.forEach accepts an object and an iterator function. It then runs the iterator
function over each enumerable property/value of the object. This function also works on
arrays.
angular.forEach({"a": 12, "b": 34}, (value, key) => console.log("key: " + key + ",
value: " + value))
// key: a, value: 12
// key: b, value: 34
81 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.fromJson
The function angular.fromJson will deserialize a valid JSON string and return an Object or
an Array.
angular.fromJson(string|object)
angular.fromJson([1, 2])
// [1, 2]
typeof angular.fromJson(new Date())
// "object"
82 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.identity
angular.identity(42)
// 42
83 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.isArray
angular.isArray(value)
Examples
angular.isArray([]) // true
angular.isArray([2, 3]) // true
angular.isArray({}) // false
angular.isArray(17) // false
84 Module 3 : AngularJS
Module 3 :Built-in helper Functions
Angular.isDate
The angular.isDate function returns true if and only if the object
passed to it is of the type Date.
angular.isDate(value)
angular.isFunction:
The function angular.isFunction determines and returns true if
and only if the value passed to is a reference to a function.
85 Module 3 : AngularJS
Module 3 :Built-in helper Functions
angular.merge:
The function angular.merge takes all the enumerable properties from the source object
to deeply extend the destination object.
angular.merge(destination, source)
86 Module 3 : AngularJS
Module 3 :AngularJS with Typescript
https://www.dotnetcurry.com/angularjs/1303/using-typescript-
angularjs-modules-controllers
87 Module 3 : AngularJS
88