create a simple web application using Visual studio
Step 2:
add type script file with name of TSFunction.ts
write a class
class TSFunction {
public authorname: string = "";
}
Step4:
compile the code and you can see respective JS file below the TS file tree view.
Step 5:
add homepage.html and drag the TSFunction.js file to the head section
<head>
<meta charset="utf-8" />
<title></title>
<script src="TSFunction.js"></script>
</head>
Step 6:
After adding this reference you can call the TS fucntion class by creating the object and you can access the metods as like our C# code. below is the code
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script src="TSFunction.js"></script>
</head>
<body>
<script>
var TS = new TSFunction();
TS.authorname = "Vamsi function";
var name = TS.authorname;
alert(TS.authorname)
alert(name)
var ts = new TSFunction();
ts.authorname = "MY Test function";
var name = ts.authorname;
alert(name)
</script>
</body>
</html>
Step 7:
Build the solution and you can see any errors under intelligence tab if nothing good to go
Step 8:
Browse the html page and find the out put
No comments:
Post a Comment