Professional Documents
Culture Documents
5
5
} }
} }
=====================================================================
note:- in the above program Angular Framework will create object for service class
and
it will inject the object within the components through Dependency injection
Mechanism
with the help of that reference variable ms we can access MyService class
variabless,methods
===========================================================================
1. create a Folder in F Drive with name Demo
2. open visualstudio code-------->New file
3.
class Employee
{
eno:number;
ename:string;
salary:number;
da:number;
hra:number;
tsal:number;
constructor(no:number,name:string,sal:number)
{
this.eno=no;
this.ename=name;
this.salary=sal;
}
CalDa()
{
this.da=0.2*this.salary;
}
CalHra()
{
this.hra=0.4*this.salary;
}
CalTsal()
{
this.tsal=this.salary+this.da+this.hra;
}
DispEmpData()
{
console.log("Eno is "+this.eno);
console.log("Ename is "+this.ename);
console.log("Basic Salary is "+this.salary);
console.log("Da is "+this.da);
console.log("Hra is "+this.hra);
console.log("Tsal is "+this.tsal);
}
}
var e1:Employee=new Employee(101,"anil",20000);
e1.CalDa(); //calling the method means the logic that was writtejn inside
e1.CalHra(); the method will gets executed
e1.CalTsal();
e1.DispEmpData();
4. save the program in D:/Demo with name emp.ts
go to terminal---->New terminal---->
F:
cd Demo
5. compile the program
tsc emp.ts
6. run the program
node emp