Recall & Review
beginner
What is a custom structural directive in Angular?
A custom structural directive changes the structure of the DOM by adding or removing elements based on logic you define. It controls how elements appear or disappear.
Click to reveal answer
beginner
Which Angular decorator is used to create a structural directive?
The @Directive decorator is used to create a structural directive. You add a selector without an asterisk (*) because the asterisk is a template syntax sugar, not part of the selector.
Click to reveal answer
intermediate
What is the role of TemplateRef and ViewContainerRef in a custom structural directive?
TemplateRef represents the template to be added or removed. ViewContainerRef is the place in the DOM where the template is inserted or removed.
Click to reveal answer
beginner
How do you use the
* prefix in Angular templates with structural directives?The
* prefix is shorthand telling Angular to treat the element as a structural directive. It expands the directive to wrap the element's template.Click to reveal answer
intermediate
What happens if you call
viewContainer.clear() inside a structural directive?Calling
viewContainer.clear() removes all inserted views from the DOM, effectively hiding or removing the elements controlled by the directive.Click to reveal answer
Which Angular class lets you insert or remove elements in a structural directive?
✗ Incorrect
ViewContainerRef controls where and how views are inserted or removed in the DOM.
What does the asterisk (*) before a directive name in a template mean?
✗ Incorrect
The * prefix tells Angular to treat the directive as structural, changing the DOM layout.
Which decorator is used to define a custom structural directive?
✗ Incorrect
@Directive is used to create directives, including structural ones.
In a custom structural directive, what does TemplateRef represent?
✗ Incorrect
TemplateRef represents the template content that can be added or removed.
What is the effect of calling
viewContainer.createEmbeddedView(templateRef)?✗ Incorrect
This method inserts the template into the DOM at the location of the view container.
Explain how you create and use a custom structural directive in Angular.
Think about how the directive controls DOM elements by adding or removing templates.
You got /4 concepts.
Describe the difference between TemplateRef and ViewContainerRef in the context of structural directives.
One is about the content, the other about where to put it.
You got /3 concepts.