Javscript and Angular Js
Javscript and Angular Js
Video Tutorial
Full Playlist Available on
YouTube Channel UPCISS
JavaScript Introduction
JavaScript Variables
JavaScript Reserved Words
JavaScript Output
JavaScript Statements
JavaScript Operators
JavaScript Data Types
JavaScript Functions
JavaScript Objects
Conditional Statements
JavaScript Popup Boxes
JavaScript Events
JavaScript Form Validation
AngularJS
1
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Easy learning: The user can learn to code in scripting languages quickly, not
much knowledge of web technology is required.
Fast editing: It is highly efficient with the limited number of data structures
and variables to use.
Interactivity: It helps in adding visualization interfaces and combinations in
web pages. Modern web pages demand the use of scripting languages. To create
enhanced web pages, fascinated visual description which includes background
and foreground colors and so on.
Functionality: There are different libraries which are part of different scripting
languages. They help in creating new applications in web browsers and are
different from normal programming languages.
2
Website: www.upcissyoutube.com YouTube Channel: UPCISS
BASIS FOR
SERVER-SIDE SCRIPTING CLIENT-SIDE SCRIPTING
COMPARISON
Basic Works in the back end which Works at the front end
dynamic websites.
JavaScript Introduction
JavaScript is a cross-platform, object-oriented scripting language used to make
webpages interactive (e.g., having complex animations, clickable buttons, popup
menus, etc.). JavaScript contains a standard library of objects, such
as Array, Date, and Math, and a core set of language elements such as operators,
control structures, and statements.
3
Website: www.upcissyoutube.com YouTube Channel: UPCISS
The example below "finds" an HTML element (with id="demo"), and changes the
element content (innerHTML) to "Hello JavaScript":
<html>
<body>
<button type="button"
onclick='document.getElementById("demo").innerHTML = "Hello
JavaScript!"'>Click Me! </button>
</body>
</html>
<button type="button"
onclick="document.getElementById('demo').style.fontSize='35px'">Click
Me!</button>
<button type="button"
onclick="document.getElementById('demo').style.display='none'">Click
Me!</button>
4
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Syntax
JavaScript syntax is the set of rules, how JavaScript programs are constructed:
JavaScript Values
The JavaScript syntax defines two types of values:
Fixed values
Variable values
JavaScript Literals
The two most important syntax rules for fixed values are:
10.50
1001
"John Doe"
'John Doe'
5
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Where To
The <script> Tag
In HTML, JavaScript code is inserted between <script> and </script> tags.
<script>
document.getElementById("demo").innerHTML = "My First JavaScript";
</script>
Scripts can be placed in the <body>, or in the <head> section of an HTML page, or in
both.
<html>
<head>
<script>
function myFunction() {
document.getElementById("demo").innerHTML = "Paragraph
changed.";
}
</script>
</head>
<body>
<h2>JavaScript in Head</h2>
</body>
</html>
Placing scripts at the bottom of the <body> element improves the display speed,
because script interpretation slows down the display.
6
Website: www.upcissyoutube.com YouTube Channel: UPCISS
External JavaScript
Scripts can also be placed in external files:
External scripts are practical when the same code is used in many different web
pages.
To use an external script, put the name of the script file in the src (source)
attribute of a <script> tag:
<html>
<body>
<h2>External JavaScript</h2>
<script src="myScript.js"></script>
</body>
</html>
For example, a function can be called when an event occurs, like when the user
clicks a button.
You will learn much more about functions and events in later chapters.
7
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Variables
Variables
Variables are containers for storing data (values).
In this example, x, y, and z, are variables, declared with the var keyword:
Using var
Using let
Using const
<body>
<h2>JavaScript Variables</h2>
<p id="demo"></p>
<script>
var x = 5;
var y = 6;
var z = x + y;
document.getElementById("demo").innerHTML =
"The value of z is: " + z;
</script>
</body>
Example
var price1 = 5;
var price2 = 6;
var total = price1 + price2;
8
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Identifiers
All JavaScript variables must be identified with unique names.
Identifiers can be short names (like x and y) or more descriptive names (age, sum,
totalVolume).
The general rules for constructing names for variables (unique identifiers) are:
9
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript can handle many types of data, but for now, just think of numbers and
strings.
Strings are written inside double or single quotes. Numbers are written without
quotes.
Example
var pi = 3.14;
var person = "John Doe";
var answer = 'Yes I am!';
var carName;
After the declaration, the variable has no value (technically it has the value
of undefined).
carName = "Volvo";
You can also assign a value to the variable when you declare it:
Start the statement with var and separate the variables by comma:
10
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Value = undefined
In computer programs, variables are often declared without a value. The value can
be something that has to be calculated, or something that will be provided later,
like user input.
The variable carName will have the value undefined after the execution of this
statement:
Example
var carName;
The variable carName will still have the value "Volvo" after the execution of these
statements:
Example
var carName = "Volvo";
var carName;
JavaScript Let
The let keyword was introduced in ES6 (2015).
Cannot be Redeclared
Variables defined with let cannot be redeclared.
11
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
let x = "John Doe";
let x = 0;
Example
var x = "John Doe";
var x = 0;
Block Scope
Before ES6 (2015), JavaScript had only Global Scope and Function Scope.
ES6 introduced two important new JavaScript keywords: let and const.
Variables declared inside a { } block cannot be accessed from outside the block:
Example
{
let x = 2;
}
// x can NOT be used here
Variables declared with the var keyword can NOT have block scope.
Variables declared inside a { } block can be accessed from outside the block.
Example
{
var x = 2;
}
// x CAN be used here
12
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Redeclaring Variables
Redeclaring a variable using the let keyword can solve this problem.
Redeclaring a variable inside a block will not redeclare the variable outside the
block:
Example
let x = 10;
// Here x is 10
{
let x = 2;
// Here x is 2
}
// Here x is 10
Let Hoisting
Variables defined with var are hoisted to the top and can be initialized at any time.
Example
This is OK:
carName = "Volvo";
var carName;
Variables defined with let are also hoisted to the top of the block, but not
initialized.
Meaning: Using a let variable before it is declared will result in a Reference Error:
Example
carName = "Saab";
let carName = "Volvo";
13
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Output
JavaScript Display Possibilities
JavaScript can "display" data in different ways:
Using innerHTML
To access an HTML element, JavaScript can use
the document.getElementById(id) method.
The id attribute defines the HTML element. The innerHTML property defines the HTML
content:
Example
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = 5 + 6;
</script>
</body>
</html>
14
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Using document.write()
For testing purposes, it is convenient to use document.write():
Example
<!DOCTYPE html>
<html>
<body>
<script>
document.write(5 + 6);
</script>
</body>
</html>
Using document.write() after an HTML document is loaded, will delete all existing
HTML:
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
Using window.alert()
You can use an alert box to display data:
15
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
<!DOCTYPE html>
<html>
<body>
<script>
window.alert(5 + 6);
</script>
</body>
</html>
In JavaScript, the window object is the global scope object, that means that
variables, properties, and methods by default belong to the window object. This
also means that specifying the window keyword is optional:
JavaScript Print
JavaScript does not have any print object or print methods.
The only exception is that you can call the window.print() method in the browser to
print the content of the current window.
Example
<!DOCTYPE html>
<html>
<body>
</body>
</html>
16
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Statements
JavaScript Programs
A computer program is a list of "instructions" to be "executed" by a computer.
JavaScript Statements
JavaScript statements are composed of:
This statement tells the browser to write "Hello Dolly." inside an HTML element with
id="demo":
Example
document.getElementById("demo").innerHTML = "Hello Dolly.";
The statements are executed, one by one, in the same order as they are written.
JavaScript programs (and JavaScript statements) are often called JavaScript code.
Semicolons ;
Semicolons separate JavaScript statements.
17
Website: www.upcissyoutube.com YouTube Channel: UPCISS
The following lines are equivalent:
let x = y + z;
If a JavaScript statement does not fit on one line, the best place to break it is after
an operator:
Example
document.getElementById("demo").innerHTML =
"Hello Dolly!";
One place you will find statements grouped together in blocks, is in JavaScript
functions:
Example
function myFunction() {
document.getElementById("demo1").innerHTML = "Hello Dolly!";
document.getElementById("demo2").innerHTML = "How are you?";
}
Comments
Single line comments start with //.
18
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Operators
JavaScript Arithmetic Operators
19
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Operator Precedence
Operator precedence describes the order in which operations are performed in an
arithmetic expression.
let x = 100 + 50 * 3;
Is the result of example above the same as 150 * 3, or is it the same as 100 +
150?
20
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Multiplication (*) and division (/) have higher precedence than addition (+) and
subtraction (-).
When using parentheses, the operations inside the parentheses are computed first.
When many operations have the same precedence (like addition and subtraction),
they are computed from left to right:
let x = 100 + 50 - 3;
21 () Expression grouping (3 + 4)
20 . Member person.name
20 [] Member person["name"]
21
Website: www.upcissyoutube.com YouTube Channel: UPCISS
16 ** Exponentiation (ES2016) 10 ** 2
15 * Multiplication 10 * 5
15 / Division 10 / 5
15 % Division Remainder 10 % 5
14 + Addition 10 + 5
14 - Subtraction 10 - 5
11 == Equal x == y
11 != Unequal x != y
22
Website: www.upcissyoutube.com YouTube Channel: UPCISS
8 | Bitwise OR x|y
6 || Logical OR x || y
5 ?? Nullish Coalescing x ?? y
3 += Assignment x += y
3 /= Assignment x /= y
3 -= Assignment x -= y
3 *= Assignment x *= y
3 %= Assignment x %= y
3 ^= Assignment x ^= y
3 |= Assignment x |= y
1 , Comma 5,6
23
Website: www.upcissyoutube.com YouTube Channel: UPCISS
let x = 16 + "Volvo";
Result: 16Volvo
Does it make any sense to add "Volvo" to sixteen? Will it produce an error or will it
produce a result?
When adding a number and a string, JavaScript will treat the number as a string.
let x = 16 + 4 + "Volvo";
Result: 20Volvo
let x = "Volvo" + 16 + 4;
Result: Volvo164
24
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
let x; // Now x is undefined
x = 5; // Now x is a Number
x = "John"; // Now x is a String
JavaScript Strings
A string (or a text string) is a series of characters like "John Doe".
Strings are written with quotes. You can use single or double quotes:
You can use quotes inside a string, as long as they don't match the quotes
surrounding the string:
Example
let answer1 = "It's alright"; // Single quote inside double quotes
let answer2 = "He is called 'Johnny'"; // Single quotes inside double quotes
let answer3 = 'He is called "Johnny"'; // Double quotes inside single quotes
JavaScript Numbers
JavaScript has only one type of numbers.
Example
let x1 = 34.00; // Written with decimals
let x2 = 34; // Written without decimals
25
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Booleans
Booleans can only have two values: true or false.
Example
let x = 5;
let y = 5;
let z = 6;
(x == y) // Returns true
(x == z) // Returns false
JavaScript Arrays
JavaScript arrays are written with square brackets.
The following code declares (creates) an array called cars, containing three items
(car names):
Example
const cars = ["Saab", "Volvo", "BMW"];
Array indexes are zero-based, which means the first item is [0], second is [1], and
so on.
JavaScript Objects
JavaScript objects are written with curly braces {}.
Example
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
26
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
typeof "" // Returns "string"
typeof "John" // Returns "string"
typeof "John Doe" // Returns "string"
typeof 0 // Returns "number"
typeof 314 // Returns "number"
typeof 3.14 // Returns "number"
typeof (3) // Returns "number"
typeof (3 + 4) // Returns "number"
Undefined
In JavaScript, a variable without a value, has the value undefined. The type is
also undefined.
Example
let car; // Value is undefined, type is undefined
car = undefined; // Value is undefined, type is undefined
Empty Values
An empty value has nothing to do with undefined.
Example
let car = ""; // The value is "", the typeof is "string"
27
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Functions
A JavaScript function is a block of code designed to perform a particular task.
Example
function myFunction(p1, p2) {
return p1 * p2; // The function returns the product of p1 and p2
}
Function names can contain letters, digits, underscores, and dollar signs (same
rules as variables).
Function parameters are listed inside the parentheses () in the function definition.
Function arguments are the values received by the function when it is invoked.
Inside the function, the arguments (the parameters) behave as local variables.
28
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Function Invocation
The code inside the function will execute when "something" invokes (calls) the
function:
You will learn a lot more about function invocation later in this tutorial.
Function Return
When JavaScript reaches a return statement, the function will stop executing.
If the function was invoked from a statement, JavaScript will "return" to execute
the code after the invoking statement.
Functions often compute a return value. The return value is "returned" back to
the "caller":
Example
Calculate the product of two numbers, and return the result:
function myFunction(a, b) {
return a * b; // Function returns the product of a and b
}
Why Functions?
You can reuse code: Define the code once, and use it many times.
You can use the same code many times with different arguments, to produce
different results.
29
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Accessing a function without () will return the function object instead of the
function result.
Example
function toCelsius(fahrenheit) {
return (5/9) * (fahrenheit-32);
}
document.getElementById("demo").innerHTML = toCelsius;
Local Variables
Variables declared within a JavaScript function, become LOCAL to the function.
Example
// code here can NOT use carName
function myFunction() {
let carName = "Volvo";
// code here CAN use carName
}
Since local variables are only recognized inside their functions, variables with the
same name can be used in different functions.
Local variables are created when a function starts, and deleted when the function is
completed.
30
Website: www.upcissyoutube.com YouTube Channel: UPCISS
JavaScript Objects
Real Life Objects, Properties, and Methods
In real life, a car is an object.
A car has properties like weight and color, and methods like start and stop:
All cars have the same properties, but the property values differ from car to car.
All cars have the same methods, but the methods are performed at different
times.
JavaScript Objects
You have already learned that JavaScript variables are containers for data values.
Objects are variables too. But objects can contain many values.
This code assigns many values (Fiat, 500, white) to a variable named car:
The values are written as name:value pairs (name and value separated by a
colon).
31
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Object Definition
You define (and create) a JavaScript object with an object literal:
Example
const person = {firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};
Spaces and line breaks are not important. An object definition can span multiple
lines:
Example
const person = {
firstName: "John",
lastName: "Doe",
age: 50,
eyeColor: "blue"
};
Object Properties
The name:values pairs in JavaScript objects are called properties:
firstName John
lastName Doe
age 50
eyeColor blue
objectName.propertyName or objectName["propertyName"]
32
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Object Methods
Objects can also have methods.
firstName John
lastName Doe
age 50
eyeColor blue
Example
const person = {
firstName: "John",
lastName : "Doe",
id : 5566,
fullName : function() {
return this.firstName + " " + this.lastName;
}
};
In the example above, this is the person object that "owns" the fullName function.
33
Website: www.upcissyoutube.com YouTube Channel: UPCISS
objectName.methodName()
name = person.fullName();
If you access a method without the () parentheses, it will return the function
definition:
Conditional Statements
Conditional statements are used to perform different actions based on different
conditions.
Very often when you write code, you want to perform different actions for different
decisions.
The if Statement
Use the if statement to specify a block of JavaScript code to be executed if a
condition is true.
Syntax
if (condition) {
// block of code to be executed if the condition is true
}
Note that if is in lowercase letters. Uppercase letters (If or IF) will generate a
JavaScript error.
34
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
Make a "Good day" greeting if the hour is less than 18:00:
if (condition) {
// block of code to be executed if the condition is true
} else {
// block of code to be executed if the condition is false
}
Example
If the hour is less than 18, create a "Good day" greeting, otherwise "Good
evening":
Syntax
if (condition1) {
// block of code to be executed if condition1 is true
} else if (condition2) {
// block of code to be executed if the condition1 is false and condition2
is true
} else {
// block of code to be executed if the condition1 is false and condition2
is false
}
35
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
If time is less than 10:00, create a "Good morning" greeting, if not, but time is less
than 20:00, create a "Good day" greeting, otherwise a "Good evening":
Syntax
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
36
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
The getDay() method returns the weekday as a number between 0 and 6.
This example uses the weekday number to calculate the weekday name:
switch (3) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
It is not necessary to break the last case in a switch block. The block breaks (ends)
there anyway.
Note: If you omit the break statement, the next case will be executed even if the
evaluation does not match the case.
37
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Example
The getDay() method returns the weekday as a number between 0 and 6.
If today is neither Saturday (6) nor Sunday (0), write a default message:
switch (3) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
In this example case 4 and 5 share the same code block, and 0 and 6 share
another code block:
Example
switch (new Date().getDay()) {
case 4:
case 5:
text = "Soon it is Weekend";
break;
case 0:
case 6:
text = "It is Weekend";
break;
default:
text = "Looking forward to the Weekend";
}
38
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Alert Box
An alert box is often used if you want to make sure information comes through to
the user.
When an alert box pops up, the user will have to click "OK" to proceed.
Syntax
window.alert("sometext");
Example
alert("I am an alert box!");
Confirm Box
A confirm box is often used if you want the user to verify or accept something.
When a confirm box pops up, the user will have to click either "OK" or "Cancel" to
proceed.
If the user clicks "OK", the box returns true. If the user clicks "Cancel", the box
returns false.
Syntax
window.confirm("sometext");
Example
if (confirm("Press a button!")) {
txt = "You pressed OK!";
} else {
39
Website: www.upcissyoutube.com YouTube Channel: UPCISS
txt = "You pressed Cancel!";
}
Prompt Box
A prompt box is often used if you want the user to input a value before entering a
page.
When a prompt box pops up, the user will have to click either "OK" or "Cancel" to
proceed after entering an input value.
If the user clicks "OK" the box returns the input value. If the user clicks "Cancel"
the box returns null.
Syntax
window.prompt("sometext","defaultText");
Example
let person = prompt("Please enter your name", "Harry Potter");
let text;
if (person == null || person == "") {
text = "User cancelled the prompt.";
} else {
text = "Hello " + person + "! How are you today?";
}
JavaScript Events
HTML events are "things" that happen to HTML elements.
HTML Events
An HTML event can be something the browser does, or something a user does.
40
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Often, when events happen, you may want to do something.
HTML allows event handler attributes, with JavaScript code, to be added to HTML
elements.
Example
<button onclick="document.getElementById('demo').innerHTML = Date()">The time
is?</button>
In the example above, the JavaScript code changes the content of the element with
id="demo".
In the example above, the JavaScript code changes the content of the element with
id="demo".
In the next example, the code changes the content of its own element
(using this.innerHTML):
Example
<button onclick="this.innerHTML = Date()">The time is?</button>
JavaScript code is often several lines long. It is more common to see event
attributes calling functions:
Example
<button onclick="displayDate()">The time is?</button>
41
Website: www.upcissyoutube.com YouTube Channel: UPCISS
onchange
onclick
42
Website: www.upcissyoutube.com YouTube Channel: UPCISS
onmouseover / onmouseout
onkeydown / onkeyup
onkeyup
onload
<script>
function myFunction() {
alert("Page is loaded");
}
</script>
43
Website: www.upcissyoutube.com YouTube Channel: UPCISS
If a form field (fname) is empty, this function alerts a message, and returns false,
to prevent the form from being submitted:
JavaScript Example
function validateForm() {
let x = document.forms["myForm"]["fname"].value;
if (x == "") {
alert("Name must be filled out");
return false;
}
}
If a form field (fname) is empty, the required attribute prevents this form from
being submitted:
44
Website: www.upcissyoutube.com YouTube Channel: UPCISS
Data Validation
Data validation is the process of ensuring that user input is clean, correct, and
useful.
Server side validation is performed by a web server, after input has been sent to
the server.
45
Website: www.upcissyoutube.com YouTube Channel: UPCISS
AngularJS
AngularJS History
AngularJS version 1.0 was released in 2012.
The idea turned out very well, and the project is now officially supported by
Google.
AngularJS Introduction
AngularJS is perfect for Single Page Applications (SPAs).
AngularJS extends HTML attributes with Directives, and binds data to HTML
with Expressions.
AngularJS is distributed as a JavaScript file, and can be added to a web page with a
script tag:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.mi
n.js"></script>
The ng-model directive binds the value of HTML controls (input, select, textarea)
to application data.
46
Website: www.upcissyoutube.com YouTube Channel: UPCISS
AngularJS Example
<!DOCTYPE html>
<html lang="en-US">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.mi
n.js"></script>
<body>
<div ng-app="">
<p>Name : <input type="text" ng-model="name"></p>
<h1>Hello {{name}}</h1> (ng-bind="name")
</div>
</body>
</html>
Example explained:
The ng-app directive tells AngularJS that the <div> element is the "owner" of an
AngularJS application.
The ng-model directive binds the value of the input field to the application
variable name.
The ng-bind directive binds the content of the <p> element to the application
variable name.
AngularJS Directives
As you have already seen, AngularJS directives are HTML attributes with
an ng prefix.
AngularJS Example
<div ng-app="" ng-init="firstName='John'">
</div>
You can use data-ng-, instead of ng-, if you want to make your page HTML valid.
47
Website: www.upcissyoutube.com YouTube Channel: UPCISS
AngularJS Applications
AngularJS modules define AngularJS applications.
The ng-app directive defines the application, the ng-controller directive defines
the controller.
AngularJS Example
<div ng-app="myApp" ng-controller="myCtrl">
AngularJS Module
var app = angular.module('myApp', []);
AngularJS Controller
app.controller('myCtrl', function($scope) {
$scope.firstName= "John";
$scope.lastName= "Doe";
});
48
Website: www.upcissyoutube.com YouTube Channel: UPCISS
AngularJS Expressions
AngularJS expressions are written inside double braces: {{ expression }}.
AngularJS Example
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.mi
n.js"></script>
<body>
<div ng-app="">
<p>My first expression: {{ 5 + 5 }}</p>
</div>
</body>
</html>
If you remove the ng-app directive, HTML will display the expression as it is,
without solving it:
You can write expressions wherever you like, AngularJS will simply resolve the
expression and return the result.
Change the color of the input box below, by changing its value:
Example
<div ng-app="" ng-init="myCol='lightblue'">
</div>
AngularJS Numbers
<div ng-app="" ng-init="quantity=1; price=5">
<h2>Cost Calculator</h2>
Quantity: <input type="number" ng-model="quantity">
Price: <input type="number" ng-model="price">
<h3>Total in Rupee: <span ng-bind="quantity * price"></span></h3>
</div>
49
Website: www.upcissyoutube.com YouTube Channel: UPCISS
https://upcissyoutube.com/
50