10 examples of 'angularjs get selected option' in JavaScript

Every line of 'angularjs get selected option' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
66getSelectedOption(key) {
67 return this.$refs.select2.options[this.selectedIndex()].dataset[key];
68}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

607function getAndUpdateSelectedOption(viewValue) {
608 var option = options.getOptionFromViewValue(viewValue);
609 var element = option && option.element;
610
611 if (element && !element.selected) element.selected = true;
612
613 return option;
614}
63protected getOptionSelected(
64 currentValue: any,
65 keyOfValue: string,
66 options: (SelectOption | SelectOptionWithChildren)[],
67): SelectOption | undefined {
68
69 let optionSelected: SelectOption | undefined;
70
71 for (const option of options) {
72 if (this.isAnOptionWithChildren(option)) {
73 optionSelected = this.getOptionSelected(currentValue, keyOfValue, option.children!);
74 } else {
75 const typeOfValue = typeof option[keyOfValue];
76
77 /**
78 * If the type is a number, the equal must be soft to match, ex:
79 * 1 == "1" -> true
80 *
81 * If the type is other, the equiality can be hard, because,
82 * when the currentValue is a string that contains "[object Object]"
83 * if you test it against an object, it will be true, ex:
84 * "[object Object]" == {} -> true
85 * "[object Object]" === {} -> false
86 *
87 */
88 if (typeOfValue === "string" || typeOfValue === "number") {
89 // tslint:disable-next-line:triple-equals
90 optionSelected = option[keyOfValue] == currentValue ? option : undefined;
91 } else {
92 optionSelected = option[keyOfValue] === currentValue ? option : undefined;
93 }
94 }
95
96 if (optionSelected) {
97 break;
98 }
99 }
100
101 return optionSelected;
102}
216get selectedOption() {
217 return this.options.find(option => option.selected);
218}
45public getSelectedValue(): any {
46 if (this.multiple && this.value.length === 1) {
47 return this.selectedDisplayValue(this.value[0]);
48 } else {
49 const index = this.options.findIndex(item => equal(this.value, item));
50 return index >= 0 ? this.selectedDisplayValue(this.options[index]) : undefined;
51 }
52}
32get selectedOptions() {
33 return this.model;
34}
42get selectedOption(): IListOption<number> {
43 return this.options.options.find(option => option.value === this.value);
44}
49get selectedOption(): IListOption<string> {
50 return this.options.options.find(option => option.value === this.value);
51}
207private setSingleSelectedOption(option: SelectItem | undefined) {
208 const previous = this.selectedItems.length > 0 ? this.optionsMap[this.selectedItems[0].value] : undefined;
209 this.selected = option ? this.optionsMap[option.value] : undefined;
210 return previous;
211}
215function isOptionSelected(option: DebugElement): boolean {
216 return option.classes[classes.optionsItemSelected];
217}

Related snippets