Angular · Senior · Question 18 of 75
A recursive tree node component needs its parent node. Which injection option fits?
export class TreeNode {
parent = inject(TreeNode, { skipSelf: true, optional: true });
}- ✓Correct answer:
skipSelfso resolution starts from the parent element, plusoptionalfor the root node - 2
selfso only the current element is checked - 3
host, which always returns the root node
Explanation
Without skipSelf, the node would find itself. self limits lookup to the current element injector; host stops at the host component's boundary.