ebook img

Learning Angular PDF

447 Pages·2023·7.528 MB·English
Save to my drive
Quick download
Download
Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.

Preview Learning Angular

Learning Angular Fourth Edition A no-nonsense guide to building web applications with Angular Aristeidis Bampakos Pablo Deeleman BIRMINGHAM—MUMBAI Learning Angular Fourth Edition Copyright © 2023 Packt Publishing All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews. Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book. Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information. Senior Publishing Product Manager: Suman Sen Acquisition Editor – Peer Reviews: Gaurav Gavas Project Editor: Meenakshi Vijay Content Development Editor: Shazeen Iqbal Copy Editor: Safis Editing Technical Editor: Srishty Bhardwaj Proofreader: Safis Editing Indexer: Hemangini Bari Presentation Designer: Rajesh Shirsath Developer Relations Marketing Executive: Priyadarshini Sharma First published: April 2016 Second edition: December 2017 Third edition: September 2020 Fourth edition: February 2023 Production reference: 2230223 Published by Packt Publishing Ltd. Livery Place 35 Livery Street Birmingham B3 2PB, UK. ISBN 978-1-80324-060-2 www.packt.com Contributors About the authors Aristeidis Bampakos has over 20 years of experience in the software development industry. He is a Greek national who currently works in Athens as a Web Development Team Leader at Plex-Earth, specializing in the development of web applications using Angular. He studied Computer Technology at the University of Portsmouth and in 2002 he was awarded the degree of Bachelor of Engineering with Second Class Honours (Upper Division). In 2004, he completed his MSc in Telecommunications Technology at Aston University. His career started as a C# .NET developer, but he saw the potential of web development and moved toward it in early 2011. He began working with AngularJS, and Angular later on, and in 2020 he was officially recognized as a Google Developer Expert (GDE) for Angular. Aristeidis is passionate about helping the developer community learn and grow. His love for teach- ing has led him to become an award-winning author of 2 successful book titles about Angular (Learning Angular – 3rd edition and Angular Projects – 2nd edition), as well as an Angular Senior Tech Instructor at Code.Hub, where he nurtures aspiring Angular developers and professionals. In his spare time, he enjoys being an occasional speaker in meetups, conferences, and podcasts, where he talks about Angular. He is currently leading the effort of making Angular accessible to the Greek development community by maintaining the open-source Greek translation of the official Angular documentation. To my pet bunny Elpida (Hope), my writing companion in this authoring journey and my best friend during the last 10 years. R.I.P. Pablo Deeleman has contributed to the dev community with several books on Angular since 2016, all published by Packt Publishing. With sound expertise in front-end libraries and frameworks such as Backbone.js, Knockout.js, VueJS, React, Svelte, AngularJs, and Angular, Pablo Deeleman has developed his career since 1998 as a JavaScript engineer across a broad range of successful companies, such as Gameloft, Red Hat or Dynatrace, just to name a few. He currently works as Staff Software Engineer at Twilio, the global leader in customer engagement communications. I’d like to thank my team at Twilio and the awesome bunch of passionate individuals that support and challenge me to become a better professional each day: Gemma Gelida, David Luna, Natalia Venditto, Adrián González, Rafael Marfil, Andreia Leite, and many more. I’d like to personally thank Aristeidis Bampakos for driving this editorial franchise to an unparalleled level of excellence. About the reviewers Jurgen Van de Moere is a front-end architect based in Belgium. He began his career in 1999 and worked for more than a decade as a web developer and system engineer for large companies across Europe. In 2012, driven by his passion for web technologies, Jurgen decided to specialise in JavaScript and Angular. Since then, he has helped many leading businesses succeed in building secure, maintainable, testable, and scalable Angular applications. In his mission to continually share his knowledge with others, Jurgen serves as a private advisor and mentor to world-renowned businesses and developers around the world. You won’t find Jurgen in the spotlight very often as he loves to spend time with his family, reading books, and writing articles. His writings impact thousands of developers a day and are regularly featured by some of the leading publishers in the tech industry. Jurgen is actively involved in growing the Belgian Angular community as co-organizer of NG-BE, Belgium’s first ever Angular conference. In 2016, he was awarded through the Google GDE pro- gram as the first ever Google Developer Expert in Belgium for web technologies. You can reach Jurgen at [email protected], follow him on Twitter at https://twitter.com/ jvandemo or read his articles on https://jvandemo.com. Santosh Yadav works as a Senior Software Engineer at Celonis and is a GDE for Angular, GitHub Star, and an Auth0 Ambassador. He loves contributing to Angular and its ecosystem. He is co-founder of This is Learning. He is also the author of the Ngx-Builders package and part of the NestJsAddOns core Team. He is also running This is Tech Talks talk show, where he invites in- dustry experts to discuss different technologies. You can find him on Twitter (@SantoshYadavDev). I would like to dedicate this book to my wife, Rekha, and daughter, Hiya. Also, I would like to thank Lars Gyrup, Brink Nielsen, Tanay Pant, Anuj Tripathi, Sajith Karad, and my teammates at Celonis for all the help they provided through the year and for keeping me motivated. Join our community on Discord Join our community’s Discord space for discussions with the author and other readers: https://packt.link/LearningAngular4e Table of Contents Preface xix Chapter 1: Building Your First Angular Application 1 Technical requirements ������������������������������������������������������������������������������������������������������ 2 What is Angular? ����������������������������������������������������������������������������������������������������������������� 2 Why choose Angular? ���������������������������������������������������������������������������������������������������������� 3 Cross-platform • 3 Tooling • 4 Onboarding • 4 Who uses Angular? • 4 Setting up the Angular CLI workspace �������������������������������������������������������������������������������� 5 Prerequisites • 5 Node.js • 5 npm • 6 Git • 6 Installing the Angular CLI • 6 CLI commands • 7 Creating a new project • 8 Structure of an Angular application ����������������������������������������������������������������������������������� 11 Components • 12 Modules • 12 Template syntax • 13 viii Table of Contents VS Code tooling ������������������������������������������������������������������������������������������������������������������ 15 Angular Language Service • 15 Angular Snippets • 17 Nx Console • 17 Material icon theme • 18 EditorConfig • 18 Angular Evergreen • 18 Rename Angular Component • 20 Summary �������������������������������������������������������������������������������������������������������������������������� 20 Chapter 2: Introduction to TypeScript 23 The history of TypeScript �������������������������������������������������������������������������������������������������� 24 The benefits of TypeScript • 24 Introducing TypeScript resources • 25 The official website • 25 The official wiki documentation • 25 Types �������������������������������������������������������������������������������������������������������������������������������� 26 String • 26 Declaring variables • 27 The let keyword • 27 The const keyword • 27 Number • 28 Boolean • 28 Array • 28 Dynamic typing with no type • 29 Custom types • 29 Enum • 30 Void • 31 Type inference • 31 Functions, lambdas, and execution flow ���������������������������������������������������������������������������� 31 Annotating types in functions • 31 Table of Contents ix Function parameters in TypeScript • 32 Optional parameters • 32 Default parameters • 33 Rest parameters • 34 Function overloading • 34 Arrow functions • 35 Common TypeScript features ������������������������������������������������������������������������������������������� 36 Spread parameter • 36 Template strings • 37 Generics • 37 Optional chaining • 39 Nullish coalescing • 40 Classes, interfaces, and inheritance ���������������������������������������������������������������������������������� 40 Anatomy of a class • 40 Constructor parameters with accessors • 42 Interfaces • 43 Class inheritance • 47 Decorators ������������������������������������������������������������������������������������������������������������������������ 48 Class decorators • 48 Extending a class decorator • 49 Property decorators • 50 Method decorators • 52 Parameter decorator • 53 Advanced types ����������������������������������������������������������������������������������������������������������������� 54 Partial • 54 Record • 54 Union • 55 Modules ���������������������������������������������������������������������������������������������������������������������������� 55 Summary �������������������������������������������������������������������������������������������������������������������������� 56

See more

The list of books you might like

Most books are stored in the elastic cloud where traffic is expensive. For this reason, we have a limit on daily download.