0
0
Angularframework~5 mins

Custom structural directives in Angular - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AElementRef
BTemplateRef
CViewContainerRef
DRenderer2
What does the asterisk (*) before a directive name in a template mean?
AIt makes the directive a component
BIt marks the directive as structural
CIt disables the directive
DIt binds the directive to a service
Which decorator is used to define a custom structural directive?
A@Directive
B@Injectable
C@Component
D@NgModule
In a custom structural directive, what does TemplateRef represent?
AThe place to insert elements
BThe host element
CThe directive's class
DThe template to be rendered
What is the effect of calling viewContainer.createEmbeddedView(templateRef)?
AIt inserts the template into the DOM
BIt updates the component's state
CIt changes the directive's selector
DIt removes the template from the DOM
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.