Angular Basics 2
Angular Basics 2
syntax:-
let arrname:datatype[]=[values]
eg:
let numlist1:number[]=[10,20,30];
let fruits:string[]=["mango","apple","grapes"];
_________________________________________________
**for-of loop
used to iterate over the values of any collection like any array in a forward
direction
for(let tempvar:collection){...}
eg:
let numlist1:number[]=[10,20,30];
for(let n of numlist1){
console.log(n);
}
output:- 10 20 30
_________________________________________________
**for-in loop
used to iterate over the index any collection like any array
let numlist1:number[]=[10,20,30];
for(let n1 in numlist1){
console.log(n1s);
}
output:-0 1 2
Lab1)create an array holding car brands & print it in a sorted manner using for-of
loop.Also add more elements using push method [array & for-of]
Lab2)create a array holding team scores [use push method to add score of 10
members].Print the highest & lowest & average score of the team
_________________________________________________
**Functions
------------
A function is a block of code which performs some task.It may or may not return the
value. If no return type, void to be written.
//function call
greet();
greet();
myfunc(34,45);
myfunc(25);
myfunc();
myfunc(10,20,30)
myfunc(10,20)
let a:number[]=[10,20,30];
myfunc(a)
myfunc([77,88,99,33])
Lab 3)
write a function printMarksheet receiving parameters rollno,name,marks-array
which needs to print marksheet details as follows
rollno=..
student name=..
total=..
percentage=..
**write 2 more functions calTotal & calPercentage & invoke them from printMarksheet
Lab 4)
write a function printBookInfo receiving
bookcode,title,author,price,discount[optional]
output:-
Book Code = ...
Book Title= ...
Book Author= ...
Book Price= ...
NO Discount / Discounted Price=..
Lab5)
write a function productInfo receiving
proCode,proName,price with default parameters
productInfo()
productInfo(1023,"Speakers",4500);
_________________________________________________
**importing Modules
import {..} from 'path of the ts file w/o extension'
eg:-
import { greet } from "./myfunc";
myfunc.ts
----------
export function greet(){
console.log("Welcome to Typescript");
}
callfunc.ts
------------
import { greet } from './myfunc'
//caller code
greet();
__________________________________________________________
Lab6)
create 2 files
myfunc.ts
----------
write 4 functions add,subtract,multiply,divide
[pass default parameter]
caller.ts
----------
call all the above 4 functions
_________________________________________________________
-when we define a function inside a class,we dont use the keyword function
function globalfunc():void{....}
class MyClass{
localfunc():void{....}
}
___________________________________________________________
Lab7)Player.ts
write a class Player having data members
playerId,playerName,country,numMatches
TestPlayer.ts
create the array of Player objects & print it using for-of loop
__________________________________________________________
Inheritance
-----------
class A{....}
class B extends A{....}
eg:-
Every derivd class has 'is-a' relationship with its base class.
class Employee{empId,empName,jdate}
let earr:Employee[]=[];
earr.push(new Manager(....));
earr.push(new WageEmployee(....));
**super keyword is available to evry subclass to access any member of super class.
Bowler.ts
------------
Write a class Bowler extends Player-->numWickets
ctor,DisplayInfo
caller.ts
---------
create an array of Player type---team holding 2 Batsman object & 2 Bowler objects
& display all players using for-of loop
eg:
let p1:Batsman=new Batsman(........);
let p2: Bowler=new Bowler(.........);
let team:Player[]=[p1,p2];
here p1 is a Batsman object
& p2 is a Bowler object
_________________________________________________________