Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Getting Started with Angular - Second edition - Second Edition

You're reading from  Getting Started with Angular - Second edition - Second Edition

Product type Book
Published in Feb 2017
Publisher Packt
ISBN-13 9781787125278
Pages 278 pages
Edition 2nd Edition
Languages
Author (1):
Minko Gechev Minko Gechev
Profile icon Minko Gechev

Table of Contents (16) Chapters

Getting Started with Angular Second Edition
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface
1. Get Going with Angular 2. The Building Blocks of an Angular Application 3. TypeScript Crash Course 4. Getting Started with Angular Components and Directives 5. Dependency Injection in Angular 6. Working with the Angular Router and Forms 7. Explaining Pipes and Communicating with RESTful Services 8. Tooling and Development Experience

Hooking into the component's life cycle


Components in Angular have a well-defined life cycle, which allows us to hook into different phases of it and have further control over our application. We can do this by implementing specific methods in the component's controller. In order to be more explicit, thanks to the expressiveness of TypeScript, we can implement different interfaces associated with the life cycle's phases. Each of these interfaces has a single method, which is associated with the phase itself.

Although code written with explicit interface implementation will have better semantics, since Angular supports ES5 as well, within the component we can simply define methods with the same names as the life cycle hooks (but this time, prefixed with ng) and take advantage of duck typing.

The following diagram shows all the phases we can hook into:

Figure 10

Let's take a look at the different life cycle hooks:

  • OnChanges: This hook will be invoked once a change in the input properties of...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}