Advanced Web Designing
Advanced Web Designing
SUCHIKA PATEL
SDJ INTERNATIONAL COLLEGE, PALSANA
Unit-1 Concepts of NoSQL: MongoDB
• In the early 1970, Flat File Systems are used. Data were stored in flat files and the
biggest problems with flat files are each company implement their own flat files
and there are no standards. It is very difficult to store data in the files, retrieve
data from files because there is no standard way to store data.
• Then the relational database was created by E.F. Codd and these databases
answered the question of having no standard way to store data. But later
relational database also gets a problem that it could not handle big data, due to
this problem there was a need of database which can handle every types of
problems then NoSQL database was developed.
Advantages of NoSQL
MongoDB
MongoDB Advantages
o Easy to use
o Light Weight
o Extremely faster than RDBMS
Data Description
Types
String String is the most commonly used datatype. It is used to store data. A string
must be UTF 8 valid in mongodb.
Integer Integer is used to store the numeric value. It can be 32 bit or 64 bit
depending on the server you are using.
Boolean This datatype is used to store boolean values. It just shows YES/NO values.
Min/Max This datatype compare a value against the lowest and highest bson
Keys elements.
Arrays This datatype is used to store a list or multiple values into a single key.
Date This datatype stores the current date or time in unix time format. It makes
you possible to specify your own date time by creating object of date and
pass the value of date, month, year into it.
Create a Database
From the Databases tab, click the Create Database button to bring up the Create Database
dialog.
• In the dialog, enter the name of the database to create and its first collection. Both
the database name and the collection name are required.
• If you want to create a capped collection, select the Capped Collection checkbox and
enter the maximum bytes.
• If you want to use custom collation on the newly created collection, select the Use
Custom Collation checkbox and select the desired collation settings.
Unit-1 Concepts of NoSQL: MongoDB
3. Click Create Database to create the database and its first collection.
Drop a Database
From the Databases tab, to delete a database, click on the trash can icon for that database. A
confirmation dialog appears.
Collections Screen
• The Collections screen lists the existing collections and views in the selected
database.
• Each list item includes the name and other general information for the collection or
view.
• To access the Collections screen for a database, from the Databases screen either:
✓ Click a Database Name in the main Databases view, or
✓ Click a database in the left navigation.
Unit-1 Concepts of NoSQL: MongoDB
Collection Information
The Collections screen displays the following information for each collection in the selected
database:
• Collection name
• Number of documents in the collection
• Average size of documents in the collection
• Total size of all documents in the collection
• Number of indexes on the collection
• Total size of all indexes on the collection
• Collation properties for the collection. Hover over a Collation banner to view the
properties for that collection.
Create a Collection
You can create new collections in an existing database.
✓ If you want to create a capped collection, select the Capped Collection checkbox and
enter the maximum bytes.
✓ If you want to use custom collation on the collection, select the Use Custom
Collation checkbox and select the desired collation settings.
Drop a Collection
1. Click the trash can icon to delete a collection.
From the Collections screen, click on the trash can for the collection to delete. A
confirmation dialog appears.
show dbs
use databasename
db
To delete database
Show collections
To create collections
db.createCollection(‘collectionName’)
To delete collections
db.<collectionname>.drop()
1.3 CRUD operations (Insert, update, delete, find, Query and Projection
operators)
Insert
The create or insert operations are used to insert or add new documents in the collection. If
a collection does not exist, then it will create a new collection in the database. You can
perform, create operations using the following methods provided by the MongoDB:
Method Description
Example: 1
Unit-1 Concepts of NoSQL: MongoDB
In this example, we are inserting details of a single student in the form of document in the
student collection using db.collection.insertOne() method.
Example 2:
In this example, we are inserting details of the multiple students in the form of documents
in the student collection using db.collection.insertMany() method.
Unit-1 Concepts of NoSQL: MongoDB
Update
The update operations are used to update or modify the existing document in the collection.
You can perform update operations using the following methods provided by the MongoDB:
Method Description
Example 1:
In this example, we are updating the age of Sumit in the student collection
using db.collection.updateOne() method. method.
Example 2:
In this example, we are updating the year of course in all the documents in the student
collection using db.collection.updateMany() method.
Unit-1 Concepts of NoSQL: MongoDB
Delete
The delete operation are used to delete or remove the documents from a collection. You
can perform delete operations using the following methods provided by the MongoDB:
Method Description
Example 1:
In this example, we are deleting a document from the student collection
using db.collection.deleteOne() method.
Find
The Read operations are used to retrieve documents from the collection, or in other words,
read operations are used to query a collection for a document. You can perform read
operation using the following method provided by the MongoDB:
Unit-1 Concepts of NoSQL: MongoDB
Method Description
Example 1:
In this example, we are retrieving the details of students from the student collection
using db.collection.find() method.
query document Optional. Specifies selection filter using query operators. To return
all documents in a collection, omit this parameter or pass an empty
document ({}).
projection document Optional. Specifies the fields to return in the documents that match
the query filter. To return all fields in the matching documents, omit
this parameter.
Unit-1 Concepts of NoSQL: MongoDB
1.3 Operators (Projection, update, limit (), sort ()) and Aggregation
Name Description
$gte Matches values that are greater than or equal to a specified value.
$lte Matches values that are less than or equal to a specified value.
$ne Matches all values that are not equal to a specified value.
Example
Logical
Name Description
$and Joins query clauses with a logical AND returns all documents that match the conditions of
both clauses.
$not Inverts the effect of a query expression and returns documents that do not match the
query expression.
$nor Joins query clauses with a logical NOR returns all documents that fail to match both
clauses.
Unit-1 Concepts of NoSQL: MongoDB
Name Description
$or Joins query clauses with a logical OR returns all documents that match the conditions of
either clause.
Array
Name Description
$all Matches arrays that contain all elements specified in the query.
$elemMatch Selects documents if element in the array field matches all the
specified $elemMatch conditions.
Projection Operators
Name Description
$ Projects the first element in an array that matches the query condition.
$slice Limits the number of elements projected from an array. Supports skip
and limit slices.
limit ()
Unit-1 Concepts of NoSQL: MongoDB
db.writers.find().pretty().limit(2)
Skip()
db.writers.find().pretty().skip(1)
sort ()
• For sorting your MongoDB documents, you need to make use of the sort() method.
• This method will accept a document that has a list of fields and the order for sorting.
• For indicating the sorting order, you have to set the value 1 or -1 with the specific
entity based on which the ordering will be set and displayed.
• One indicates organizing data in ascending order while -1 indicates organizing in
descending order.
• Db.test.find.sort({age:1})
Aggregation commands
• MongoDB's aggregate function will cluster out the records in the form of a collection
which can be then employed for providing operations like total number(sum), mean,
minimum and maximum, etc. from the aggregated group of data extracted.
• For performing such an aggregate function, the aggregate() method is used. The
syntax of this method looks something like this:
db.collection_name.aggregate(aggregate_operation)
Expression Description
$sum adds up the definite values of every documentUnit-1
of a Concepts
collection.
of NoSQL: MongoDB
$min finds and returns the minimum of all values from within a collection.
$max finds and returns the maximum of all values from within a collection.
Example:
• db.test.aggregate([
... { $group: {_id: "$age", count:{$sum:1}}}])
• The world can't live without mobile and web applications in this day and age.
Everything is digitized, from booking cabs to ordering food to make bank transactions.
Thanks to the efficient frameworks that provide a seamless user experience. One such
robust frontend library is React.
2.1.1 Concepts of React.
Why React?
• Easy creation of dynamic applications: React makes it easier to create dynamic web
applications because it requires less coding and offers more functionality, as opposed
to JavaScript, where coding often gets complex very quickly.
• Improved performance: React uses Virtual DOM, thereby creating web applications
faster. Virtual DOM compares the components’ previous states and updates only the
items in the Real DOM that were changed, instead of updating all of the components
again, as conventional web applications do.
• Reusable components: Components are the building blocks of any React application,
and a single app usually consists of multiple components. These components have
their logic and controls, and they can be reused throughout the application, which in
turn dramatically reduces the application’s development time.
• Unidirectional data flow: React follows a unidirectional data flow. This means that
when designing a React app, developers often nest child components within parent
components. Since the data flows in a single direction, it becomes easier to debug
errors and know where a problem occurs in an application at the moment in question.
• Small learning curve: React is easy to learn, as it mostly combines basic HTML and
JavaScript concepts with some beneficial additions. Still, as is the case with other tools
and frameworks, you have to spend some time to get a proper understanding of
React’s library.
• It can be used for the development of both web and mobile apps: We already know
that React is used for the development of web applications, but that’s not all it can do.
There is a framework called React Native, derived from React itself, that is hugely
popular and is used for creating beautiful mobile applications. So, in reality, React can
be used for making both web and mobile applications.
Unit-2: Fundamentals of React.js
• Dedicated tools for easy debugging: Facebook has released a Chrome extension that
can be used to debug React applications. This makes the process of debugging React
web applications faster and easier.
1. Functional Components
ReactDOM.render(
<React.StrictMode>
<Demo />
</React.StrictMode>,
document.getElementById('root')
);
const Demo=()=>
{
Unit-2: Fundamentals of React.js
2. Class Components
• The class components are a little more complex than the functional components.
• The functional components are not aware of the other components in your program
whereas the class components can work with each other.
• We can pass data from one class component to other class components. We can use
JavaScript ES6 classes to create class-based components in React. Below example
shows a valid class-based component in React.
function Car(props) {
Pass Data
• Props are also how you pass data from one component to another, as parameters.
function Car(props) {
return <h2>I am a { props.brand }!</h2>;
}
function Garage() {
return (
<>
<h1>Who lives in my garage?</h1>
<Car brand="Ford" />
</>
);
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Garage />);
Unit-2: Fundamentals of React.js
• When creating a React component, the component's name must start with an upper-
case letter.
• The component has to include the extends React.Component statement, this
statement creates an inheritance to React.Component, and gives your component
access to React.Component's functions.
• The component also requires a render() method, this method returns HTML.
render() {
To use this component in your application, use similar syntax as normal HTML: <Car />
Component Constructor
• If there is a constructor() function in your component, this function will be called when
the component gets initiated.
• The constructor function is where you initiate the component's properties.
• In React, component properties should be kept in an object called state.
• The constructor function is also where you honor the inheritance of the parent
component by including the super() statement, which executes the parent
component's constructor function, and your component has access to all the functions
of the parent component (React.Component).
constructor() {
super();
render() {
Unit-2: Fundamentals of React.js
Components in Components
render() {
render() {
return (
<div>
<Car />
</div>
); } }
root.render(<Garage />);
• if Statement
Example:
function MissedGoal() {
return <h1>MISSED!</h1>;
Unit-2: Fundamentals of React.js
function MadeGoal() {
return <h1>GOAL!</h1>;
}
function Goal(props) {
const isGoal = props.isGoal;
if (isGoal) {
return <MadeGoal/>;
}
return <MissedGoal/>;
}
Operators
Logical && Operator
import React from 'react';
import ReactDOM from 'react-dom/client';
function Garage(props) {
const cars = props.cars;
return (
<>
<h1>Garage</h1>
{cars.length > 0 &&
<h2>
You have {cars.length} cars in your garage.
</h2>
}
</>
);
}
function MissedGoal() {
return <h1>MISSED!</h1>;
}
function MadeGoal() {
return <h1>GOAL!</h1>;
}
function Goal(props) {
const isGoal = props.isGoal;
return (
<>
{ isGoal ? <MadeGoal/> : <MissedGoal/> }
</>
);
}
Lists
function Car(props) {
function Garage() {
return (
<>
<ul>
</ul>
</>
);
const root =
ReactDOM.createRoot(document.getElementById('root'));
root.render(<Garage />);
Example:
function Car(props) {
function Garage() {
const cars = [
];
return (
<>
<ul>
</ul>
</>
);
Unit-2: Fundamentals of React.js
const root =
ReactDOM.createRoot(document.getElementById('root'));
root.render(<Garage />);
• Just like HTML DOM events, React can perform actions based on user events.
• React has the same events as HTML: click, change, mouseover etc.
Adding Events
function Football() {
const shoot = () => {
alert("Great Shot!");
}
return (
<button onClick={shoot}>Take the shot!</button>
);
}
Passing Arguments
import React from 'react';
import ReactDOM from 'react-dom/client';
function Football() {
const shoot = (a) => {
alert(a);
}
return (
<button onClick={() => shoot("Goal!")}>Take the shot!</button>
);
}
Unit-2: Fundamentals of React.js
function Football() {
const shoot = (a, b) => {
alert(b.type);
/*
'b' represents the React event that triggered the function.
In this case, the 'click' event
*/
}
return (
<button onClick={(event) => shoot("Goal!", event)}>Take the shot!</button>
);
}
2. Controlled component
• In HTML, form elements typically maintain their own state and
update it according to the user input.
• In the controlled component, the input form element is handled
by the component rather than the DOM.
• Here, the mutable state is kept in the state property and will be
updated only with setState() method.
• Controlled components have functions that govern the data
passing into them on every onChange event, rather than grabbing
the data only once, e.g., when you click a submit button. This data
is then saved to state and updated with setState() method. This
makes component have better control over the form elements
and data.
• A controlled component takes its current value through props and
notifies the changes through callbacks like an onChange event.
Unit-3: Forms and Hooks in React.JS
• A parent component "controls" these changes by handling the
callback and managing its own state and then passing the new
values as props to the controlled component. It is also called as a
"dumb component."
import React, { Component } from 'react';
class App extends React.Component {
constructor(props) {
super(props);
this.state = {value: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({value: event.target.value});
}
handleSubmit(event) {
alert('You have submitted the input successfully: ' + this.state.val
ue);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleSubmit}>
<h1>Controlled Form Example</h1>
<label>
Name:
<input type="text" value={this.state.value} onChange={th
is.handleChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}
export default App;
Unit-3: Forms and Hooks in React.JS
SN Controlled Uncontrolled
1. It does not maintain its internal state. It maintains its internal states.
2. Here, data is controlled by the parent Here, data is controlled by the DOM itself.
component.
3. It accepts its current value as a prop. It uses a ref for their current values.
5. It has better control over the form elements It has limited control over the form elements
and data. and data.
function FavoriteColor() {
const [color, setColor] = useState("");
}
Read State
function FavoriteColor() {
Unit-3: Forms and Hooks in React.JS
const [color, setColor] = useState("red");
Update State
import { useState } from "react";
import ReactDOM from "react-dom/client";
function FavoriteColor() {
const [color, setColor] = useState("red");
return (
<>
<h1>My favorite color is {color}!</h1>
<button
type="button"
onClick={() => setColor("blue")}
>Blue</button>
</>
)
}
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<FavoriteColor />);
function Car() {
const [brand, setBrand] = useState("Ford");
const [model, setModel] = useState("Mustang");
const [year, setYear] = useState("1964");
const [color, setColor] = useState("red");
return (
<>
<h1>My {brand}</h1>
<p>
It is a {color} {model} from {year}.
</p>
</>
)
}
function Car() {
const [car, setCar] = useState({
brand: "Ford",
model: "Mustang",
year: "1964",
color: "red"
});
return (
<>
<h1>My {car.brand}</h1>
<p>
It is a {car.color} {car.model} from {car.year}.
</p>
</>
)
}
useEffect
• The useEffect Hook allows you to perform side effects in your
components.
• Some examples of side effects are: fetching data, directly updating the
DOM, and timers.
• useEffect accepts two arguments. The second argument is optional.
useEffect(<function>, <dependency>)
import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";
function Timer() {
const [count, setCount] = useState(0);
useEffect(() => {
setTimeout(() => {
setCount((count) => count + 1);
}, 1000);
});
Unit-3: Forms and Hooks in React.JS
return <h1>I've rendered {count} times!</h1>;
}
• useEffect runs on every render. That means that when the count changes,
a render happens, which then triggers another effect.
• We should always include the second parameter which accepts an array.
We can optionally pass dependencies to useEffect in this array.
No dependency passed
useEffect(() => {
//Runs on every render
});
An empty array
useEffect(() => {
//Runs only on the first render
}, []);
function Counter() {
const [count, setCount] = useState(0);
const [calculation, setCalculation] = useState(0);
useEffect(() => {
setCalculation(() => count * 2);
}, [count]); // <- add the count variable here
return (
<>
<p>Count: {count}</p>
<button onClick={() => setCount((c) => c + 1)}>+</button>
<p>Calculation: {calculation}</p>
</>
);
}
Unit-3: Forms and Hooks in React.JS
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<Counter />);
Effect Cleanup
• Some effects require cleanup to reduce memory leaks.
• Timeouts, subscriptions, event listeners, and other effects that are no
longer needed should be disposed.
• A return function at the end of the useEffect Hook.
import { useState, useEffect } from "react";
import ReactDOM from "react-dom/client";
function Timer() {
const [count, setCount] = useState(0);
useEffect(() => {
let timer = setTimeout(() => {
setCount((count) => count + 1);
}, 1000);
useContext
• To set the global data and this data can now be accessed in any of the
children’s components without the need to pass it through every parent
Component.
• Syntax
const authContext = useContext(initialValue);
The use Context accepts the value provided
by React.createContext and then re-render the component whenever its
value changes but you can still optimize its performance by
using memoization.
AuthContext.js
import React from 'react';
function App() {
const [inputValue, setInputValue] = useState("");
const count = useRef(0);
useEffect(() => {
count.current = count.current + 1;
});
return (
<>
<input
type="text"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
<h1>Render Count: {count.current}</h1>
</>
);
}
const root =
ReactDOM.createRoot(document.getElementById('root'));
Unit-3: Forms and Hooks in React.JS
root.render(<App />);
function App() {
const inputElement = useRef();
return (
<>
<input type="text" ref={inputElement} />
<button onClick={focusInput}>Focus Input</button>
</>
);
}
useReducer
useReducer(<reducer>, <initialState>)
• The reducer function contains your custom state logic and the initial State
can be a simple value but generally will contain an object.
Unit-3: Forms and Hooks in React.JS
• The useReducer Hook returns the current state and a dispatch method.
const initialTodos = [
{
id: 1,
title: "Todo 1",
complete: false,
},
{
id: 2,
title: "Todo 2",
complete: false,
},
];
function Todos() {
const [todos, dispatch] = useReducer(reducer, initialTodos);
return (
<>
{todos.map((todo) => (
<div key={todo.id}>
<label>
<input
type="checkbox"
checked={todo.complete}
onChange={() => handleComplete(todo)}
/>
{todo.title}
Unit-3: Forms and Hooks in React.JS
</label>
</div>
))}
</>
);
}
useCallback
• The React useCallback Hook returns a memoized callback function.
• This allows us to isolate resource intensive functions so that they will not
automatically run on every render.
• The useCallback Hook only runs when one of its dependencies update.
• This can improve performance.
• One reason to use useCallback is to prevent a component from re-
rendering unless its props have changed.
index.js
return (
<>
<Todos todos={todos} addTodo={addTodo} />
<hr />
Unit-3: Forms and Hooks in React.JS
<div>
Count: {count}
<button onClick={increment}>+</button>
</div>
</>
);
};
Todos.js
import { memo } from "react";
useMemo
• The React useMemo Hook returns a memorized value.
• The useMemo Hook only runs when one of its dependencies update.
• This can improve performance.
• The useMemo Hook can be used to keep expensive, resource intensive
functions from needlessly running.
return (
<div>
<div>
<h2>My Todos</h2>
{todos.map((todo, index) => {
return <p key={index}>{todo}</p>;
})}
<button onClick={addTodo}>Add Todo</button>
</div>
<hr />
<div>
Count: {count}
<button onClick={increment}>+</button>
<h2>Expensive Calculation</h2>
{calculation}
</div>
</div>
);
};
• React.Js provides lots of built-in hooks that you can use in your React
apps.
• You can make your own custom hooks and use it in your apps resulting
in better readability and a reduced amount of code.
• Custom hooks are normal JavaScript functions whose names start with
“use” and they may call other hooks(built-in or custom).
Custom hooks give us following benefits:
• When a piece of code (logic) is reused in many places (it’s easy to see
when you copy a whole piece of code without editing anything, except
for the parameter passed. Split like how you separate a function).
• When the logic is too long and complicated, you want to write it in
another file, so that your component is shorter and easier to read
because you don’t need to care about the logic of that hook anymore.
Features
• Data Model Binding – You don’t need to write special code to bind data
to the HTML controls. This can be done by Angular by just adding a few
snippets of code.
Numbers
AngularJS numbers are similar to JavaScript numbers.
<!DOCTYPE html>
<html>
<script
src="http://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: {{ quantity * cost }}</p>
</div>
</body>
</html>
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/an
gular.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>
</html>
Unit-4: Angular JS
Strings
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/an
gular.min.js"></script>
<body>
<div ng-app="" ng-init="firstName='Sonoo';lastName='Jaiswal'">
<p>My full name is: {{ firstName + " " + lastName }}</p>
</div>
</body>
</html>
Objects
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/an
gular.min.js"></script>
<body>
<div ng-app="" ng-
init="person={firstName:'Sonoo',lastName:'Jaiswal'}">
<p>My name is {{ person.firstName }}</p>
</div>
</body>
</html>
Arrays
<!DOCTYPE html>
<html>
Unit-4: Angular JS
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/an
gular.min.js"></script>
<body>
<div ng-app="" ng-init="points=[1,15,19,2,40]">
<p>The first result is {{ points[0] }}</p>
</div>
</body>
</html>
• You can download the AngularJS script file, when you click on download
button. You can download Minified, Uncompressed or in Zip file format.
• If you downloaded the zip file, then unzip it and copy and paste
angularjs.min.js file in your visual studio project folder.
Angular JS Filters
In AngularJS, filters are used to format data. Following is a list of filters used for
transforming data.
Filter Description
• You can add filters to expressions by using the pipe character |, followed
by a filter.
• In this example, the uppercase filter format strings to upper case:
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
"></script>
<body>
<div ng-app="myApp" ng-controller="personCtrl">
<p>The name is {{ firstName | uppercase }}</p>
</div>
<script>
angular.module('myApp', []).controller('personCtrl', function($scope) {
$scope.firstName = "Sonoo",
$scope.lastName = "Jaiswal"
});
</script>
</body>
</html>
model objects. The controller receives input, validates it, and then
performs business operations that modify the state of the data model.
ng-app
• ng-app directive defines the root element.
• It starts an AngularJS Application and automatically initializes or
bootstraps the application when web page containing AngularJS
Application is loaded.
• It is also used to load various AngularJS modules in AngularJS Application.
ng-init
• ng-init directive initializes an AngularJS Application data. It defines the
initial values for an AngularJS application.
• In following example, we'll initialize an array of countries. We're using
JSON syntax to define array of countries.
Unit-4: Angular JS
ng-controller
• The AngularJS ng-controller directive adds a controller class to the view
(your application). It is the key aspect which specifies the principles
behind the Model-View-Controller design pattern.
• It facilitates you to write code and make functions and variables, which
will be parts of an object, available inside the current HTML element. This
object is called scope.
• This is supported by all HTML elements.
• Syntax <element ng-controller="expression"></element>
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
"></script>
<body>
<div ng-app="myApp" ng-controller="myCtrl">
Full Name: {{firstName + " " + lastName}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
$scope.firstName = "Aryan";
$scope.lastName = "Jaiswal";
});
</script>
Unit-4: Angular JS
<p>In this example you can see how to define a controller, and how to use vari
ables made for the scope.</p>
</body>
</html>
ng-model
• ng-model directive defines the model/variable to be used in AngularJS
Application.
• In following example, we've defined a model named "name".
ng-repeat
• ng-repeat directive repeats html elements for each item in a collection. In
following example, we've iterated over array of countries.
<ol>
<li ng-repeat = "country in countries">
{{ 'Country: ' + country.name + ', Locale: ' + country.locale }}
</li>
</ol>
Unit-4: Angular JS
font-family:Verdana;
}
</style>
<body ng-app="">
<p>Choose a class:</p>
<select ng-model="home">
<option value="normal">Normal</option>
<option value="medium">Medium</option>
<option value="advance">Advance</option>
</select>
<div ng-class="home">
<h1>Hello</h1>
<p>World</p>
</div>
</body>
</html>
ng-animate
• In angularjs ngAnimate module will provide a CSS based animation
transitions effect to elements while performing show/hide or fade in /
fade out, etc. events.
• In angularjs ngAnimate module will add/remove some pre-defined CSS
classes to HTML elements to provide animation effect whenever certain
events raised like show/hide elements.
<!DOCTYPE html>
<html>
<head>
<title>AngularJS Animations Example</title>
<script src="http://ajax.googleapis.com/ajax/libs/angular
js/1.4.8/angular.min.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angular
js/1.4.8/angular-animate.js"></script>
<script type="text/javascript">
var app = angular.module("angularapp", ["ngAnimate"]);
</script>
Unit-4: Angular JS
<style>
div
{
transition: all linear 0.5s;
background-color: #08c;
width: 30%;
padding:30px;
border:1px solid black;
}
.ng-hide {
opacity:0;
}
</style>
</head>
<body ng-app="angularapp">
<h2>AngularJS Animations Example</h2>
Show / Hide Div <input type="checkbox" ng-
model="chkselct"><br /><br />
<div ng-hide='chkselct' style="clear:both;">Hi Welcome to
Angularjs... Hello World</div>
</body>
</html>
The following are some of the directives that supports animation effect.
• ng-repeat
• ng-view
• ng-include
• ng-show / hide
• ng-switch
• ng-if
• Whenever ng-show / hide events raised ngAnimate module is used ng-
hide class to add/remove animation effect.
ng-show
• The AngularJS ng-show directive is used to show or hide the given HTML
element according to the expression given to the ng-show attribute.
• It shows the specified HTML element if the given expression is true,
otherwise it hides the HTML element.
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
"></script>
<body ng-app="">
Show HTML element: <input type="checkbox" ng-model="myVar">
<div ng-show="myVar">
<h1>Hello</h1>
<p>Class.</p>
</div>
</body>
</html>
ng-hide
• The AngularJS ng-hide directive is used to hide the HTML element if the
expression is set to true.
• The element is shown if you remove the ng-hide CSS class and hidden, if
you add the ng-hide CSS class onto the element. The ng-hide CSS class is
predefined in AngularJS and sets the element's display to none.
• <element ng-hide="expression"></element>
As a CSS class:
• <element class="ng-hide"></element>
<!DOCTYPE html>
<html>
Unit-4: Angular JS
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js
"></script>
<body ng-app="">
Hide HTML: <input type="checkbox" ng-model="myVar">
<div ng-hide="myVar">
<h1>Welcome </h1>
<p>A solution of all technologoes.</p>
</div>
</body>
</html>
<script>
function studentController($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
Unit-4: Angular JS
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
}
</script>
• The studentController is defined as a JavaScript object with $scope as
an argument.
• The $scope refers to application which uses the studentController
object.
• The $scope.student is a property of studentController object.
• The firstName and the lastName are two properties of $scope.student
object. We pass the default values to them.
• The property fullName is the function of $scope.student object, which
returns the combined name.
• In the fullName function, we get the student object and then return the
combined name.
• As a note, we can also define the controller object in a separate JS file
and refer that file in the HTML page.
Example:
<html>
<head>
<title>Angular JS Controller</title>
<script src =
"https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js">
</script>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<script>
var mainApp = angular.module("mainApp", []);
Unit-4: Angular JS
mainApp.controller('studentController', function($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
});
</script>
</body>
</html>
Lowercase
The lowercase filter converts the string to lower case.
Unit-4: Angular JS
<!DOCTYPE html>
<html >
<head>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app>
<div ng-
init="person.firstName='James';person.lastName='Bond'">
Lower case: {{person.firstName + ' ' + person.lastName |
lowercase}} <br />
</div>
</body>
</html>
Currency
The currency filter formats a number value as a currency. When no currency
symbol is provided, default symbol for current locale is used.
<!DOCTYPE html>
<html >
<head>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="myController">
Default currency: {{person.salary | currency}} <br />
Custom currency identifier: {{person.salary |
currency:'Rs.'}} <br />
No Fraction: {{person.salary | currency:'Rs.':0}} <br />
Fraction 2: <span ng-bind="person.salary|
currency:'GBP':2"></span>
</div>
<script>
var myApp = angular.module('myApp', []);
</html>
order by
• The orderBy filter sorts an array based on specified expression predicate.
• {{ expression | orderBy : predicate_expression : reverse}}
<!DOCTYPE html>
<html>
<head>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app="myApp">
<div ng-controller="myController">
<select ng-model="SortOrder">
<option value="+name">Name (asc)</option>
<option value="-name">Name (dec)</option>
<option value="+phone">Phone (asc)</option>
<option value="-phone">Phone (dec)</option>
</select>
<ul ng-repeat="person in persons | orderBy:SortOrder">
<li>{{person.name}} - {{person.phone}}</li>
</ul>
</div>
<script>
var myApp = angular.module('myApp', []);
$scope.SortOrder = '+name';
});
</script>
</body>
</html>
Unit-5: Angular JS: Single page application
Adding a Controller:
app.controller("Controller-name", function($scope) {
$scope.variable-name= "";
});
Here, we can add any number of variables in controller and use them in the
html files, body of the tag in which the controller is added to that tag by
writing:
<body>
<div ng-app="Module-name">
<div ng-controller="Controller-name">
{{variable-name}}
</div>
Unit-5: Angular JS: Single page application
Example:
DemoComponent.js
app.controller('DemoController', function($scope) {
$scope.ch = function(choice) {
$scope.choice = "Your choice is: " + choice;
};
$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>
</head>
<body ng-app="DemoApp">
<h1>
Using controllers in Module
</h1>
<script src=
"https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js
">
Unit-5: Angular JS: Single page application
</script>
<script src="DemoApp.js"></script>
<script src="DemoController"></script>
Vowels List :
<select ng-options="option for option in list"
ng-model="mychoice" ng-change="c()">
</select>
</html>
Step 1)
• Write the below code in a file called Table.html. This is the file which will
be injected into our main application file using the ng-include directive.
• The below code snippet assumes that there is a scope variable called
“tutorial.” It then uses the ng-repeat directive, which goes through each
Unit-5: Angular JS: Single page application
topic in the “Tutorial” variable and displays the values for the ‘name’ and
‘description’ key-value pair.
<table>
<tr ng-repeat="Topic in tutorial">
<td>{{ Topic.Name }}</td>
<td>{{ Topic.Country }}</td>
</tr>
</table>
Step 2)
• let’s write the below code in a file called Main.html. This is a simple
angular.JS application which has the following aspects
1. Use the “ng-include directive” to inject the code in the external file
‘Table.html’. The statement has been highlighted in bold in the below
code. So the div tag ‘ <div ng-include=”‘Table.html'”></div>’ will be
replaced by the entire code in the ‘Table.html’ file.
2. In the controller, a “tutorial” variable is created as part of the $scope
object. This variable contains a list of key-value pairs.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Event Registration</title>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js">
</script>
</head>
Unit-5: Angular JS: Single page application
<body ng-app="sampleApp">
<div ng-controller="AngularController">
<h3> Global Event</h3>
<div ng-include="'Table.html'"></div>
</div>
<script>
});
</script>
</body>
</html>
ngRoute
• You can also use the CDN in your application to include this file. In this
tutorial, We are going to use the Google
CDN. https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-
route.min.js If you are bundling this file into your application, then you
can add it to your page with below code.
Unit-5: Angular JS: Single page application
<script src="angular-route.js">
If you want to include it from Google CDN, then use below code.
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-
route.min.js"></script>
angular.module('appName', ['ngRoute']);
ngView
• Every time the current route changes, the included view changes with it
according to the configuration of the $route service.
$routeProvider
app.config(function($routeProvider) {
$routeProvider
.when('/view1', {
templateUrl: 'view1.html',
Unit-5: Angular JS: Single page application
controller: 'FirstController'
})
.when('/view2', {
templateUrl: 'view2.html',
controller: 'SecondController'
})
.otherwise({
redirectTo: '/view1'
});
});
• path is a part of the URL after the # symbol. route contains two properties
- templateUrl and controller.
• If no route paths matches the given URL the browser will be redirected to
the path specified in the otherwise() function.
main.js
mainApp.config(function($routeProvider) {
$routeProvider
.when('/home', {
templateUrl: 'home.html',
controller: 'StudentController'
})
.when('/viewStudents', {
templateUrl: 'viewStudents.html',
controller: 'StudentController'
})
.otherwise({
redirectTo: '/home'
});
});
mainApp.controller('StudentController', function($scope) {
$scope.students = [
Unit-5: Angular JS: Single page application
{name: 'Mark Waugh', city:'New York'},
];
});
<div class="container">
<p>{{message}}</p>
</div>
This is the default page of our application. In this view, we just print out the
message, which we have already initialized in the StudentController. You can
also see a link to the viewStudents page. viewStudents.html
<div class="container">
Search:
<br/>
Unit-5: Angular JS: Single page application
<input type="text" ng-model="name" />
<br/>
<ul>
</ul>
</div>
In the above view, you can see a list of students with a search option. Finally,
follow below steps to complete our AngularJS routing example application.
index.html
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="utf-8">
<title>AngularJS Routing</title>
</head>
<body>
Unit-5: Angular JS: Single page application
<div ng-app="mainApp">
<ng-view></ng-view>
</div>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28/angular.min.js"></
script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.28//angular-
route.min.js"></script>
</body>
</html>
That’s all for our AngularJS Routing example. Our application is ready to run.
We can use various directives to bind the application data to the attributes of
DOM elements. Some of them are:
• ng-disabled
• ng-hide
• ng-click
• ng-show
5.2.1
ng-disabled
• We can use ng-disabled for disabling a given control. Attributes of HTML
elements can be disabled using ng-disabled directive.
Syntax
<input type = "checkbox" ng-model = "enableDisableButton">To disable a
button
<button ng-disabled = "enableDisableButton">Click</button>
Example
<!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="value=true">
<p><button ng-disabled="value">Click Here!!</button></p>
<p><input type="checkbox" ng-model="value"/>Button</p>
<p>{{ value }}</p>
Unit-5: Angular JS: Single page application
</div>
</body>
</html>
• The ng-model directive binds the value of the HTML checkbox element to
the value of value (In the above code value is the name of application
data).
• If the value of value evaluates to true, the button will disable and if the
value of value evaluates to false, the button will not disable
ng-show
• We can use ng-show for showing a given control.
Syntax
<input type = "checkbox" ng-model = "showHide1">To show a Button
<button ng-show = "showHide1">Click </button>
Example
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"
></script>
<body>
<div ng-app="">
<input type = "checkbox" ng-model = "showhiddenbutton">Show button
<button ng-show = "showhiddenbutton">Click Here!</button>
</div>
</body>
</html>
Unit-5: Angular JS: Single page application
• When the checkbox is checked the output displays a button of click
here! also.
Output-
(checked) Show button Click Here!
ng-hide
• We can use ng-hide for hiding a given control.
Syntax
<input type = "checkbox" ng-model = "showHide2">To hide a Button
<button ng-hide = "showHide2">Click</button>
Example
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"
></script>
<div ng-app="">
<input type = "checkbox" ng-model = "hidebutton">Hide Button
<button ng-hide = "hidebutton">Click Here!</button>
</div>
</body>
</html>
Output-
__ Hide Button Click Here!
When you checked the checkbox, the button click here! will get hidden.
ng-click
Unit-5: Angular JS: Single page application
• We can use ng-click for representing an angularjs click event.
Syntax
<p>Number of click: {{ clickCounter }}</p>
<button ng-click = "clickCounter = clickCounter + 1">Click </button>
Example
<!DOCTYPE html>
<html>
<script
src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"
></script>
<div ng-app="">
<p>Total number of Clicks: {{ Counts }}</p>
<button ng-click = "Counts = Counts+ 1">Click Here!</button>
</div>
</body>
</html>
• The number of times you will click on the button Click Here! will get
displayed corresponding to the total number of clicks.
Input controls are ways for a user to enter data. A form is a collection of controls
for the purpose of grouping related controls together.
o input elements
o select elements
Unit-5: Angular JS: Single page application
o button elements
o textarea elements
AngularJS provides multiple events that can be associated with the HTML
controls. These events are associated with the different HTML input elements.
o ng-click
o ng-dbl-click
o ng-mousedown
o ng-mouseup
o ng-mouseenter
o ng-mouseleave
o ng-mousemove
o ng-mouseover
o ng-keydown
o ng-keyup
o ng-keypress
o ng-change
Example:
<!DOCTYPE html>
<html>
<head>
<title>Angular JS Forms</title>
<script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/
angular.min.js"></script>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
Unit-5: Angular JS: Single page application
table tr:nth-child(odd) {
background-color: lightpink;
}
table tr:nth-child(even) {
background-color: lightyellow;
}
</style>
</head>
<body>
<tr>
<td>Enter last name: </td>
<td><input name = "lastname" type = "text" ng-
model = "lastName" required>
Unit-5: Angular JS: Single page application
<span style = "color:red" ng-
show = "studentForm.lastname.$dirty && studentForm.lastname.$inva
lid">
<span ng-
show = "studentForm.lastname.$error.required">Last Name is required
.</span>
</span>
</td>
</tr>
<tr>
<td>Email: </td><td><input name = "email" type = "email" n
g-model = "email" length = "100" required>
<span style = "color:red" ng-
show = "studentForm.email.$dirty && studentForm.email.$invalid">
<span ng-
show = "studentForm.email.$error.required">Email is required.</span
>
<span ng-
show = "studentForm.email.$error.email">Invalid email address.</spa
n>
</span>
</td>
</tr>
<tr>
<td>
<button ng-click = "reset()">Reset</button>
</td>
<td>
<button ng-disabled = "studentForm.firstname.$dirty &&
studentForm.firstname.$invalid || studentForm.lastname
.$dirty &&
studentForm.lastname.$invalid || studentForm.email.$dir
ty &&
studentForm.email.$invalid" ng-
click="submit()">Submit</button>
Unit-5: Angular JS: Single page application
</td>
</tr>
</table>
</form>
</div>
<script>
var mainApp = angular.module("mainApp", []);
mainApp.controller('studentController', function($scope) {
$scope.reset = function(){
$scope.firstName = "Sonoo";
$scope.lastName = "Jaiswal";
$scope.email = "[email protected]";
}
$scope.reset();
});
</script>
</body>
</html>
Data validation
AngularJS provides client-side form validation. It checks the state of the form
and input fields (input, textarea, select), and lets you notify the user about the
current state.
It also holds the information about whether the input fields have been touched,
or modified, or not.
Directive Description
ng-required Sets required attribute on an input field.
ng- Sets minlength attribute on an input field.
minlength
ng- Sets maxlength attribute on an input field. Setting the attribute to a
maxlength negative or non-numeric value, allows view values of any length.
ng-pattern Sets pattern validation error key if the ngModel value does not match
the specified RegEx expression.
<!DOCTYPE html>
<html>
<head>
<script src="~/Scripts/angular.js"></script>
</head>
<body ng-app >
<form name="studentForm" novalidate>
<label for="firstName">First Name: </label> <br />
<input type="text" name="firstName" ng-model="student.firstName"
ng-required="true" />
<span ng-show="studentForm.firstName.$touched &&
studentForm.firstName.$error.required">First name is required.</span><br
/><br />
<label for="lastName">Last Name</label><br />
<input type="text" name="lastName" ng-minlength="3" ng-
maxlength="10" ng-model="student.lastName" />
<span ng-show="studentForm.lastName.$touched &&
studentForm.lastName.$error.minlength">min 3 chars.</span>
<span ng-show="studentForm.lastName.$touched &&
studentForm.lastName.$error.maxlength">Max 10 chars.</span><br /><br />
<label for="dob">Email</label><br />
<input type="email" id="email" ng-model="student.email"
name="email" />
Unit-5: Angular JS: Single page application
<span ng-show="studentForm.email.$touched &&
studentForm.email.$error.email">Please enter valid email id.</span><br
/><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
SDJ INTERNATIONAL COLLEGE,PALSANA
11. Explain the concept of Form and Form validation in AngularJS. Write a suitable
code for the same.
12.Explain the following MongoDB Query Document operations with syntax and
example:
a. find()
b. Pretty()
c. findOne()
d. And keyword
e. Or keyword
OR
B.
1. Create Database "University"
2. Create Collection named "private"
3. Create Collection named "central_uni"
4. Insert at least 2 documents in the collection "private" and in collection
"central_uni"
5. Delete the private university having name "C.J. Shah"
6. Find central_uni university named "J.R.Roy"
7. Update the "contact no" of central uni university where c_id is "101"
8. Delete all private university from "private" collection who have category
under the "fake" list
C.
1. Create Database "movie"
2. Create Collection named "film"
3. Create Collection named "actor"
4. Insert at least 2 documents in the collection film and in collection actor
5. Delete the film "XYZ"
6. Delete an actor named "ABC"
7. Update the actor's address where actor id is "101"
8. Delete all actors from an "actor" collection who have age greater than
"50"
Q.4 Write a code for following:
1. Write an AngularJS, which accepts and validates Student Name, Email Address,
and Mobile No from the user.
2. Create a Form in React.js for Student Registration, with Name, DOB, and
password. Display the details also.
3. Create a Simple counter using React.js, which increments or decrements count
dynamically on-screen as the user clicks on buttons. Use following steps:
I. Prepare two HTML buttons, one for increment value and other for
decrement value.
II. If we click on increment button then value will be increased by 1 (e.g., 1,
2, 3, 4...).
III. If we click on decrement button then value will be decreased by 1 (e.g., 4,
3, 2, 1...).
1. Operators in MongoDB
2. React JS Events
3. SPA (Single Page Application) in Angular JS
4. Angular JS Expressions and controllers
5. MongoDB datatypes with its syntax and example.
6. Hooks in React JS
7. MVC Architecture
8. Filters in Angular js
9. CRUD Operations
10.React Events
11.MVC Architecture
12.Props with Example
***ALL TH BEST***
SDJ INTERNATIONAL COLLEGE, PALSANA.
CENTRAL_UNI
db.central_uni.insertMany([
{ name: "J.R. Roy", location: "City C", contact_no:
"1234567890", c_id: "101" },
{ name: "M.S. Sharma", location: "City D", contact_no:
"9876543210", c_id: "102" }
])
5. Delete the private university having name "C.J. Shah"
db.private.deleteOne({ name: "C.J. Shah" })
7. Update the "contact no" of central uni university where c_id is "101"
db.central_uni.updateOne(
{ c_id: "101" },
{ $set: { contact_no: "1112223334" } }
)
Q.2
1. Create Database "movie"
use movie
Q.3
db.createCollection("student")
db.student.insertMany([
])