Join Justin Schwartzenberger for an in-depth discussion in this video Basics of TypeScript, part of Angular 2 Essential Training (2016).
- View Offline
You will be using TypeScript as you learn to write code for Angular. There's a very minimal learning curve to get to where you need to be in TypeScript, with the main focus being on writing classes, using decorators, and a bit of function parameter typing that you need to be familiar with. There are two benefits of going with TypeScript to write your Angular code. The first is simplicity. By being able to write classes and use decorators, you end up writing less code that reads cleaner and is easier to follow. The second is the Angular source code.
If you're writing your code in the same fashion as the Angular source code, it'll be easy for you to look through the source code as you grow your Angular skills. The ability to reference and learn from the source code as you work on your Angular projects will increase your productivity as well as your understanding of the framework. Using the same pattern of writing code, in this case TypeScript, will provide you an accelerated benefit in that area. Let's take a quick look at some code for an Angular component and highlight the parts that are TypeScript.
At the top of this code, there's an inport statement. This is some TypeScript syntax that will handle module loading. The @Component block of code is a TypeScript decorator. Below that, there is a class definition. The class syntax is actually ES2015, but the export keyword is a TypeScript thing for turning the class into a module. Within the class, there is a constructor function, which is also an ES2015 thing, but the parameter it takes in has a colon and then a type behind it.
That is TypeScript syntax for strong typing a parameter. While these concepts seem complex now, they will make more sense as you progress through the course.
- What is Angular?
- Setting up an Angular template
- Creating a component
- Displaying data
- Working with events
- Using two-way data binding
- Creating a subcomponent
- Using the built-in HTTP module
- Using the built-in router module