Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Essential Angular

You're reading from   Essential Angular Fast paced guide to Front-end web development with Angular

Arrow left icon
Product type Paperback
Published in May 2017
Publisher Packt
ISBN-13 9781788293761
Length 108 pages
Edition 1st Edition
Tools
Arrow right icon
Authors (3):
Arrow left icon
Narwhal Technologies Inc Narwhal Technologies Inc
Author Profile Icon Narwhal Technologies Inc
Narwhal Technologies Inc
Jeff Cross Jeff Cross
Author Profile Icon Jeff Cross
Jeff Cross
Victor Savkin Victor Savkin
Author Profile Icon Victor Savkin
Victor Savkin
Arrow right icon
View More author details
Toc

Advanced topics

Controlling visibility

You can be more specific where you want to get dependencies from. For instance, you can ask for another directive on the same element.

class CustomInputComponent {
constructor(@Self() f: FormatterDirective) {}
}

Or you can ask for a directive in the same template, that is, you can only inject an ancestor directive from the same HTML file.

class CustomInputComponent {
constructor(@Host() f: CustomForm) {}
}

Finally, you can ask to skip the current element, which can be handy for decorating existing providers or building up tree-like structures.

class SomeComponent {
constructor(@SKipSelf() ancestor: SomeComponent) {}
}

Optional dependencies

To mark a dependency as optional, use the Optional decorator.

class Login {
constructor...
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 $19.99/month. Cancel anytime