Typescript, is a typed superset of the JavaScript language that is compiled to produce clean, simple cross-browser compatible JavaScript code, which can help when building and maintaining large-scale applications. Typescript has features of ES6 such as interfaces, classes and modules.
Note: To specify custom typing we can use an interface
In this example we have specified custom type for address using an interface.
User component
@Component({ selector: 'user', template: `<h1>Simple Angular 2 template </h1> <p> <strong>First Name : </strong>{{firstName}} </p> <p> <strong>Last Name : </strong>{{lastName}} </p> <p> <strong>MI : </strong>{{MI}}</p> <p> <strong>DOB : </strong>{{DOB}}</p> <p> <strong>address : </strong>{{address.Street}} {{address.City}} {{address.State}} </p> `, }) //Angular Component export class UserComponent { firstName :string; lastName :string; MI:string; DOB:string; address:address //Constructor constructor(){ this.firstName = 'Prathap'; this.lastName="Kudupu"; this.MI="H"; this.DOB="01/12/2000"; this.address={ Street:"Vallco Pkwy", City:"Cupertino", State:"CA" } } } //interface address{ interface address{ Street:string, City:string, State:string }
Index.html
<!DOCTYPE html> <html> <head> <title>Angular QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('app').catch(function(err){ console.error(err); }); </script> </head> <body> <my-app>Loading AppComponent content here ...</my-app> </body> </html>
Excellent blog. Looking for software courses?
ReplyDeletePHP Training in Chennai
web designing course in chennai
JAVA Training in Chennai
Hadoop Training in Chennai
Selenium Training in Chennai
German Classes in chennai
German Classes in Porur
The given information was excellent and useful. This is one of the excellent blog, I have come across. Do share more.
ReplyDeleteR Training in Chennai
R Programming Training in Chennai
Data Science Course in Chennai
Data Science Training in Chennai
Data Science Training in Anna Nagar
Machine Learning Course in Chennai
Machine Learning Training in Chennai
R Programming Training in Chennai
Thanks for providing such great and useful informations on your blog.update more data later.
ReplyDeleteHadoop Training in Chennai
Big data training in chennai
Big Data Hadoop Training in Chennai
JAVA Training in Chennai
Python Training in Chennai
Digital Marketing Course in Chennai
Hadoop training in chennai
Big data training in chennai
big data training in velachery