Inspecting an embedded view context
A structural directive is used to add and remove elements to the DOM throughout the lifecycle of a component. They create an embedded view, which is bound to a view context. This is the case of the NgIf
and NgFor
directives that are part of the Angular framework.
Important Note
Only one structural directive can be attached to an element. If you need to apply multiple structural directives, wrap the element in the special <ng-container>
element, attach the outer structural directive to this element, and so on.
When we pass an element with a structural directive attached to ng.getContext
, it returns the view context. For example, when we pass an element with an NgIf
directive attached to it, NgIfContext
is returned, which has the following shape:
interface NgIfContext { $implicit: boolean; ngIf: boolean; }
The embedded view that is dynamically created by NgIf
is bound to the $implicit
property of NgIfContext...