MCPcopy Index your code
hub / github.com/angular/components / Option

Class Option

src/aria/listbox/option.ts:53–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 },
52})
53export class Option<V> implements OnInit, OnDestroy {
54 /** A reference to the host element. */
55 readonly element = inject(ElementRef).nativeElement as HTMLElement;
56
57 /** Whether the option is currently active (focused). */
58 readonly active = computed(() => this._pattern.active());
59
60 /** The parent Listbox. */
61 private readonly _listbox = inject(LISTBOX);
62
63 /** A unique identifier for the option. */
64 readonly id = input(inject(_IdGenerator).getId('ng-option-', true));
65
66 /** The parent Listbox UIPattern. */
67 private readonly _listboxPattern = computed(() => this._listbox._pattern);
68
69 /** The value of the option. */
70 readonly value = input.required<V>();
71
72 /** Whether an item is disabled. */
73 readonly disabled = input(false, {transform: booleanAttribute});
74
75 /** The text used by the typeahead search. */
76 readonly label = input<string>();
77
78 /** Whether the option is selected. */
79 readonly selected = computed(() => this._pattern.selected());
80
81 /** The Option UIPattern. */
82 readonly _pattern = new OptionPattern<V>({
83 ...this,
84 id: this.id,
85 value: this.value,
86 listbox: this._listboxPattern,
87 element: () => this.element,
88 searchTerm: () => this.label() ?? '',
89 });
90
91 ngOnInit() {
92 this._listbox._collection.register(this);
93 }
94
95 ngOnDestroy() {
96 this._listbox._collection.unregister(this);
97 }
98}

Callers

nothing calls this directly

Calls 7

computedFunction · 0.85
inputFunction · 0.85
labelMethod · 0.80
activeMethod · 0.45
getIdMethod · 0.45
requiredMethod · 0.45
selectedMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…