Angular 2 comes with TypeScript support, which allows us to write reusable code more easily. How to use TypeScript in our controllers, and especially how to achieve dependency injection?
- [Voiceover] Now we move onto the final video…of this section where we're going to use TypeScript…in our controllers.…First we will need to inject our dependency…with TypeScript so we are going to learn how to do that.…Then we're going to convert our existing controllers…to TypeScript.…We've already converted our services to TypeScript…in the previous video but haven't converted…dependency injection yet.…As you know, TypeScript classes have constructors.…Which are solution to our problem.…
In the example here, I created a constructor…with two parameters.…Which are the two dependencies we're going to inject…into our controller.…Then the injection happens with a data inject function,…where a string parameters in the array are the names…of the dependencies to inject.…Please note that dependencies in that array…have to be declared in the same order…as in the class constructor.…As parameter number one, will be the first parameter…of the constructor,…number two will be the second and so on.…
Now let's talk using TypeScript in our controllers.…
Angular 2 is a technical and conceptual overhaul of its hugely popular predecessor, AngularJS. To stay ahead, developers who have built and maintained projects with AngularJS need to be able to transition them to Angular 2. Migrating to Angular 2 demonstrates how to create and execute an effective migration plan for Angular applications. It opens with an introduction to the major changes and additions brought by the new framework. Then author Alain Chautard reviews a plan to migrate a sample weather application from its original Angular 1.x codebase.
Learn how to migrate blocks of code incrementally, as opposed to porting code in bulk, and get a brief introduction to TypeScript and ECMAScript 6. Along the way, Alain shows you how to gradually deprecate $scope, upgrade services, work with the component router, transition forms, and more.
By the end of this course, you'll be up to speed with the fundamental building blocks of Angular 2 development, and fully capable (and confident) transitioning existing Angular 1.x projects to the new environment, ready to explore everything that Angular 2 has to offer.
- What's new in Angular 2?
- Migrating incrementally
- What are TypeScript and ES6?
- Cleaning up $scopes
- Making components
- Using TypeScript classes
- Upgrading 1.x services, components, and controllers
- Best practices for Angular 2