Unit V
Unit V
Introduction to AngularJS
It provides data binding capability to HTML thus giving user a rich and responsive
experience.
With AngularJS, developer write less code and get more functionality.
In AngularJS, views are pure html pages, and controllers written in JavaScript do the
business processing.
1. Model:
It is responsible for managing application data.
It responds to the requests from view and to the instructions from controller
to update itself.
2. View:
It is responsible for displaying all data or only a portion of data to the users.
It also specifies the 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.
3. Controller:
It is responsible to control the relation between models and views.
It responds to user input and performs interactions on the data model
objects.
2 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
The controller receives input, validates it, and then performs business
operations that modify the state of the data model.
Understanding ng attributes
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="">
<p>Input something in the input box:</p>
<p>Name: <input type="text" ng-model="name"></p>
<p ng-bind="name"></p>
</div>
Script Explanation
1. The AngularJS script is written within <html> tags. The AngularJS is baed on
JavaScript framework. The framework for AngularJS is loaded using <script> tag. It
is as follows-
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
2. Defining np-app directive: The np-app directive is defined in above script as follows-
3. Defining np- model directive: The textbox control is modelled using np-model
directive
<p>Name: <input type="text" ng-model="name"></p>
4. Defining np-bind: We can bind the value entered in the textbox with name using np-
bind directive
<p ng-bind="name"></p>
2. ng-init directive :
4 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
The ng-init directive is used for initialization of AngularJS data.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="" ng-init="myText='Hello World!'">
<h1>{{myText}}</h1>
<p>The ng-init directive has created an AngularJS variable, which you can use in the
application.</p>
</div>
</body>
</html>
3. ng-model: The ng-model directive binds the value of HTML control application data.
These controls can be input, select, textarea and so on. For example –
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app= “ ”>
<p>Enter your Name: <input type=“text” ng-model=“name”></p>
<p> Welcome<span ng-bind=“name”></span></p>
</div>
</body>
</html>
AngularJS expressions are much like JavaScript expressions: They can contain
literals, operators, and variables.
Example {{ 5 + 5 }} or {{ firstName + " " + lastName }}
<!DOCTYPE html> My first
<html> expression: 10
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app>
<p>My first expression: {{ 5 + 5 }}</p>
</div>
</body>
</html>
Note: If you remove the directive "ng-app", HTML will display the expression without
solving it.
1. <!DOCTYPE html>
2. <html>
3. <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
4. <body>
5. <p>If you remove the directive "ng-app", HTML will display the expression without solving it.</p>
6. <div>
7. <p>A simple expression example: {{ 5 + 5 }}</p>
8. </div>
9. </body>
</html>
AngularJS Numbers
AngularJS numbers are similar to JavaScript numbers.
<!DOCTYPE html> Total in dollar:
<html> 25
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div ng-app="" ng-init="quantity=5;cost=5">
<p>Total in dollar: <span ng-bind="quantity * cost"></span></p>
</div>
</body>
AngularJS Strings
<!DOCTYPE html> My full name
<html> is:
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> SonooJaiswal
<body>
<div ng-app="" ng-init="firstName='Sonoo';lastName='Jaiswal'">
<p>My full name is: <span ng-bind="firstName + ' ' + lastName"></span></p>
</div>
</body>
</html>
AngularJS Data Binding
Data binding is a very useful and powerful feature used in software development
technologies. It acts as a bridge between the view and business logic of the
application.
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></
script>
<body>
<div ng-app="" ng-init="firstName='Ajeet'">
<p>Input something in the input box:</p>
<p>Name: <input type="text" ng-model="firstName"></p>
<p>You wrote: {{ firstName }}</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body>
<div data-ng-app="" data-ng-init="quantity=1;price=20">
<h2>Cost Calculator</h2>
Quantity: <input type="number" ng-model="quantity">
Price: <input type="number" ng-model="price">
<p><b>Total in rupees:</b> {{quantity * price}}</p>
</div>
</body>
</html>
9 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
Conditional Directives
ng – if
ng – switch
ng-if Directive
The ng-if directive removes the HTML element if the expression evaluates to false.
If the if statement evaluates to true, a copy of the Element is added in the DOM.
Syntax
<element ng-if="expression"></element>
ng – switch
Style Directives
The ng-style directive specifies the style attribute for the HTML element.
The value of the ng-style attribute must be an object, or an expression returning an
object.
The object consists of CSS properties and values, in key value pairs.
Syntax
<element ng-style="expression"></element>
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angul
ar.min.js"></script>
<h1 ng-style="myObj">Welcome</h1>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl", function($scope) {
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "60px",
"padding" : "50px"
11 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
}
});
</script>
</body>
</html>
Controllers
<!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="myCtrl">
First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "John";
$scope.lastName = "Doe"
});
</script>
</body>
</html>
Script Explanation:
</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>
</div>
<script src="personController.js"></script>
angular.module('myApp', []).controller('personCtrl',
function($scope) {
$scope.firstName = "John",
$scope.lastName = "Doe",
$scope.fullName = function() {
return $scope.firstName + " " + $scope.lastName;
}
});
Filters
Uppercase filters
The uppercase filter converts a string to uppercase letters.
Syntax: {{ string | uppercase}}
14 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
<div ng-app="myApp" ng-controller="caseCtrl">
HELLO WORLD!
<h1>{{txt | uppercase}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('caseCtrl', function($scope) {
$scope.txt = "Hello World!";
});
</script>
Lowercase filters
The lowercase filter converts a string to lowercase letters.
Syntax: {{ string | lowercase }}
<div ng-app="myApp" ng-controller="caseCtrl"> hello world!
<h1>{{txt | lowercase}}</h1>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('caseCtrl', function($scope) {
$scope.txt = "Hello World!";
});
</script>
Currency filter
Syntax
{{ number | currency : symbol : fractionsize }}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('costCtrl', function($scope) {
$scope.price = 9.99;
});
</script>
</body>
</html>
filter Filter
The filter filter allows us to filter an array, and return an array containing only the
matching items.
This filter can only be used for arrays.
Syntax : {{ arrayexpression | filter : expression : comparator }}
Value Description
expression The expression used when selecting items from the array. The expression can be of
type:
String: The array items that match the string will be returned.
Object: The object is a pattern to search for in the array. Example: filter: {"name" :
"H", "city": "London"} will return the array items with a name containing the letter
"H", where the city contains the word "London".
</div>
<script>
var app = angular.module('myApp', []);
app.controller('arrCtrl', function($scope) {
$scope.customers = [
{"name" : "Alfreds Futterkiste", "city" : "Berlin"},
{"name" : "Around the Horn", "city" : "London"},
{"name" : "B's Beverages", "city" : "London"},
{"name" : "Bolido Comidas preparadas", "city" : "Madrid"},
{"name" : "Bon app", "city" : "Marseille"},
{"name" : "Bottom-Dollar Marketse" ,"city" : "Tsawassen"},
{"name" : "Cactus Comidas para llevar", "city" : "Buenos Aires"}
];
});
</script>
orderBy Filter
AngularJS Forms
17 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
Form is a collection of various controls
Angular JS support two types of control- Data binding and validation controls
Various controls supported by AngularJS forms are:-
o Input
o Select
o Button
o Textarea
Input control
Input controls provides data-binding by using the ng-model directive.
<input type="text" ng-model="firstname">
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="">
<form>
First Name: <input type="text" ng-model="firstname">
</form>
<h1>You entered: {{firstname}}</h1>
</div>
<p>Change the name inside the input field, and you will see the name in the header changes
accordingly.</p>
</body>
</html>
Checkbox
A checkbox has the value true or false. Apply the ng-model directive to a checkbox, and use
its value in your application.
<!DOCTYPE html>
18 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></
script>
<body>
<div ng-app="">
<form>
Check to show a header:
<input type="checkbox" ng-model="myVar">
</form>
<h1 ng-show="myVar">My Header</h1>
</div>
<p>The header's ng-show attribute is set to true when the checkbox is checked.</p>
</body>
</html>
Radio buttons
Bind radio buttons to your application with the ng-model directive.
Radio buttons with the same ng-model can have different values, but only the
selected one will be used.
<form>
Pick a topic:
<input type="radio" ng-model="myVar" value="dogs">Dogs
<input type="radio" ng-model="myVar" value="tuts">Tutorials
<input type="radio" ng-model="myVar" value="cars">Cars
</form>
Select box
Bind select boxes to your application with the ng-model directive.
The property defined in the ng-model attribute will have the value of the selected
option in the selectbox.
<form>
Select a topic:
19 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
<select ng-model="myVar">
<option value="">
<option value="dogs">Dogs
<option value="tuts">Tutorials
<option value="cars">Cars
</select>
</form>
Routers
The ngRoute module helps your application to become a Single Page Application.
If you want to navigate to different pages in your application, but you also want the
application to be a SPA (Single Page Application), with no page reloading, you can use
the ngRoute module.
The ngRoute module routes your application to different pages without reloading the
entire application.
<body ng-app="myApp">
<p><a href="#/!">Main</a></p>
<a href="#!red">Red</a>
<a href="#!green">Green</a>
<a href="#!blue">Blue</a>
<div ng-view></div>
<script>
var app = angular.module("myApp", ["ngRoute"]);
app.config(function($routeProvider) {
$routeProvider
.when("/", {
templateUrl : "main.htm"
})
.when("/red", {
templateUrl : "red.htm"
})
.when("/green", {
templateUrl : "green.htm"
})
.when("/blue", {
20 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
templateUrl : "blue.htm"
});
});
</script>
</body>
Modules
The AngularJS module defines the functionality of the application which is applied on the
entire HTML page. It helps to link many components. So it is just a group of related
components. It is a container that consists of different parts like controllers, services, and
directives.
Creating a Module in AngularJS:
var app = angular.module("Module-name", []);
<div ng-app = "module-name">
The code in which the module is required.
</div>
Adding a Controller:
app.controller("Controller-name", function($scope) {
$scope.variable-name= "";
});
Example: Implementation of the Angular JS Modules.
$scope.c = function () {
$scope.choice = "Your choice is: " + $scope.mychoice;
};
});
Module-name: DemoApp.js:
var app = angular.module('DemoApp', []);
index.html file:
<!DOCTYPE html>
<html>
<head>
<title>
Modules and Controllers in Files
</title>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js">
</script>
<script src="DemoApp.js"></script>
<script src="DemoController.js"></script>
</head>
<body ng-app="DemoApp">
<h1 style="color:green">GeeksforGeeks</h1>
<h3>AngularJS Modules</h3>
<h4>
Using controllers in Module
</h4>
<div ng-app="DemoApp"
ng-controller="DemoController">
Vowels List :
<button ng-click="ch('A')">A</button>
22 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
<button ng-click="ch('E')">E</button>
<button ng-click="ch('I')">I</button>
<button ng-click="ch('O')">O</button>
<button ng-click="ch('U')">U</button>
Vowels List :
<select ng-options="option for option in list"
ng-model="mychoice"
ng-change="c()">
</select>
</html>
Services
The services are functions or objects that are intended to carry out specific task.
In AngularJS there are 30 built-in services used to carry out variety of tasks.
Built-in services
1. The $http Service
The $http service is one of the most common used services in AngularJS
applications.
The service makes a request to the server, and lets your application handle the
response.
Step 1: Create a simple web document as follows –
Msg.html
Well Done!!!
Step 2: Now create a web document that will make use of $http service to get the
message stored in the above html file and to display the contents
<!DOCTYPE html>
<html>
<script src = "https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
<body>
<div ng-app=“MyApp”ng-controller=“MyController”>
<p>Message obtained from a file is…</p>
<h1>{{message}}</h1>
</div>
<script>
var App=angular.module(‘MyApp’,[]);
App.controller(‘My Controller’, function($scope,$http){
$http.get(“msg.html).then(function(response){
$scope.message=response.data;
});
});
</script>
</body>
</html>
<script>
var App=angular.module(‘MyApp’,[]);
App.controller(‘My Controller’, function($scope,$timeout){
$scope.message=“Welcome user”;
$timeout(function(){
$scope.message=“Good Bye!!!”;
},5000);
});
</script>
</body>
</html>
Features
1) Open source: Docker is an open source platform. That means it is freely available on
the internet for use.
2) Easy to use: It is very easy to configure the system in docker. We can easily deploy
the code in any desired environment with the help of simple commands in less time
1) Docker daemon: Docker daemon runs on the host operating system. It is responsible for
running containers to manage docker services. Docker daemon communicates with other
daemons. It offers various Docker objects such as images, containers, networking, and
storage.
2) Docker Client: Docker client uses commands and REST APIs to communicate with the
Docker Daemon (Server).
27 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
3) Docker Host: Docker Host is used to provide an environment to execute and run
applications.
4) Docker Registry: Docker Registry manages and stores the Docker images. There are two
types of registries in the Docker –
Pubic Registry - Public Registry is also called as Docker hub.
Private Registry - It is used to share images within the enterprise.
5) Docker images: Docker images are the read-only binary templates used to create Docker
Containers.
Node JS
node console_example1.js
React JS
ReactJS is an open source, component-based front end Java Script library maintained
by Facebook
This library is responsible only for the view layer of the application. That means this
JavaScript is for building user interfaces.
Features of ReactJS
JSX
JSX stands for JavaScript XML. It is a JavaScript syntax extension.
Its an XML or HTML like syntax used by ReactJS.
Components
ReactJS is all about components.
ReactJS application is made up of multiple components, and each component
has its own logic and controls.
If you have npx and Node.js installed, you can create a React application by using create-
react-app.
Now you are ready to run your first real React application!
cd my-react-app
npm start
A new browser window will pop up with your newly created React App! If not, open your
browser and type localhost:3000 in the address bar.
Versatile
Model:
Django applications use python objects called models which are used to access and
manage data. These models define the structure of data in the Django application.
It is responsible for maintaining the entire applications data’s for which it provides
various mechanisms to add, update, read and delete the data in the database.
View:
These view functions accept the web requests and deliver the web response.
Views retrieves the necessary data to fulfil the request using models and renders
them on the user interface using templates.
Template:
A template is a text file that defines the structure or layout of the user interface.
The test file can be any type of file; for example HTML, XML, etc.
Used by:
Django is used by Top MNC and companies such as Youtube, Instagram, Spotify and
Dropbox.
32
UI and UX
CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
The UI and UX are two commonly used terms in web and app design. They are
placed together in a single term UI/UX design.
What is UI?
The UI stands for user interface.
The user interface is the graphical layout of the application
UI refers to the screens, buttons, toggles, icons and other visual elements that you
interact with when using a website, app or other electronic device.
UI designers are graphics designers
They are concerned with aesthetics.
It is up to them to make sure the application’s interface is attractive, visually-
stimulating and themed appropriately to match the purpose of the app.
What is UX?
The UX stands for User Experience.
It evolved as a result of the improvement to the UI.
The user experience is determined by how easy or difficult it is to interact with the
user interface elements that the UI designers have created.
Difference between UI and UX
UI UX
UI stands for User Interface Design UX stands for User Experience Design
UI refers the aesthetic user elements within UX refers to the functional elements a user
a product interacts within a product or service
UI design is a process that mainly focuses UX design focuses on everything that
on the look and aesthetic of product design affects the user’s journey to solve a problem
It is guided by design best practices. It is guided by deep user research.
UI design is based on the user’s needs and UX design is based on the client’s needs
research. and requirements.
UX Designer Responsibilities
Here are some key responsibilities of UX designer:
Analyze the business needs and convert them into a captivating experience.
The UX designer maps out the structure of the user journey.
UX designers deal with the psychology and behavior of users and design products or
solutions that appeal to the target users.
UI Designer Responsibilities
Here are some key responsibilities of UI designer:
33 CCS375 WEB TECHNOLOGIES UNIT V PREPARED BY : Mr.V.Balamurugan, AP/CSE
Ul designers deal with the appearance and feel of the product, including colors,
texture, shape, and form.
They implement a visual hierarchy that guides the user on what to do.
UI designer fills design with visual and interactive elements.
They also take the responsibility of making the website more intuitive and
responsive.
Tools used in UI and UX
1. Figma
Figma is one of the most popular tools among designers that comes in handy for
wireframing, prototyping, and illustration. It allows good collaboration among designers and
stakeholders through its unique chat and calls features.
2. Sketch
A dedicated UI design tool for Mac later evolved and could be used on any web browser. It
saves designers time to deliver consistent prototypes, whether it’s through their library of
symbols, layer styles, or text styles, or its seamless scaling and aligning features.
3. Framer
Framer is a very powerful design tool, which can be used to create amazing and aesthetic-
looking portfolios and prototypes. Framer comes with pre-made interactive components,
polished assets, layout tools, and other features, so you can quickly create realistic websites
and apps.
Using framer-premade assets and components you may create user interfaces for MacOS,
Android, and iPhones in no time.
4. Balsamiq
A notepad-like UI wireframing tool, that gives you the feel of actual rough drawing on a
notepad. Balsamiq prevents you from becoming side tracked by colors and other elements
too early and forces you to concentrate on structure and content.
5. Adobe XD
Adobe is a big known brand when it comes to design tools. Everyone is aware of tools like
Photoshop, lightroom, after effects, and Illustrator.
The most exciting feature is the prototyping in adobe xd. These consist of 3D transforms,
repeat grids, reusable components, vector drawing tools, auto-animation, and content-
aware layouts.