What are host directives and when are they useful?
Model answer
The hostDirectives option in @Component or @Directive lets a component or directive apply other directives to its host element, and choose which of their inputs and outputs to expose. This is composition: you can combine small behaviours, such as a focus or tooltip directive, into a component without extending a base class.
It keeps behaviour reusable and avoids inheritance chains, and the consumer does not need to add the directives in the template.
Learn this topic
Angular Tutorial: Beginner to Advanced .
Sign in to add your own answer.
More questions
- What is a directive? What are the types?
- What is the difference between ngClass and ngStyle, and how do they compare with class and style bindings?
- What is a pipe? Name some built-in pipes.
- How do you create a custom pipe? What is the difference between pure and impure pipes?
- What does the async pipe do, and why is it recommended?
- How do you build a custom attribute directive?