Become a Ninja with Angular2 (Free Sample)
Total Page:16
File Type:pdf, Size:1020Kb
Become a ninja with Angular2 (free sample) Ninja Squad Table of Contents 1. Free sample . 1 2. Introduction. 2 3. A gentle introduction to ECMASCRIPT 6 . 4 3.1. Transpilers . 4 3.2. let . 5 3.3. Constants . 6 3.4. Creating objects. 7 3.5. Destructuring assignment . 7 3.6. Default parameters and values . 9 3.7. Rest operator . 11 3.8. Classes . 12 3.9. Promises . 14 3.10. Arrow functions . 18 3.11. Sets and Maps . 21 3.12. Template literals . 22 3.13. Modules . 22 3.14. Conclusion . 24 4. Going further than ES6 . 25 4.1. Dynamic, static and optional types . 25 4.2. Enters TypeScript . 26 4.3. A practical example with DI . 26 5. Diving into TypeScript . 29 5.1. Types as in TypeScript. 29 5.2. Enums . 30 5.3. Return types. 30 5.4. Interfaces . 31 5.5. Optional arguments . 31 5.6. Functions as property . 32 5.7. Classes . 32 5.8. Working with other libraries . 34 5.9. Decorators . 35 6. The wonderful land of Web Components . 38 6.1. A brave new world. 38 6.2. Custom elements . 38 6.3. Shadow DOM . 39 6.4. Template . 40 6.5. HTML imports . 41 6.6. Polymer and X-tag . 41 7. Grasping Angular’s philosophy . 44 8. From zero to something . 48 8.1. Developing and building a TypeScript app . 48 8.2. Our first component . 50 8.3. Bootstrapping the app . 52 8.4. From zero to something better with angular-cli. 55 9. End of the free sample . 57 Chapter 1. Free sample What you’re going to read is a free sample : the starting part of the full ebook, which explains its purpose and contents, gives an overview of ECMAScript 6, TypeScript, and Web Components, describes Angular 2 philosophy, and finally lets you write your first application. This sample extract does not require any preliminary knowledge. 1 Chapter 2. Introduction So you want to be a ninja, huh? Well, you’re in good hands! But we have a long road, you and me, with lots of things to learn :). We’re living exciting times in Web development. There is a new Angular. A complete rewrite of the good old AngularJS. Why a complete rewrite? Was AngularJS 1.x not enough? I like the old AngularJS very much. In our small company, we have built several projects with it, contributed code to the core framework, trained hundred of developers (yes, really), and even written a book about it (in French, but that still counts). AngularJS is incredibly productive once you have mastered it. Despite all of this, it doesn’t prevent us from seeing its weaknesses. AngularJS is not perfect, with some very difficult concepts to grasp, and traps hard to avoid. Most of all, the Web has changed since AngularJS was conceived. JavaScript has changed. New frameworks.