1

I am not sure what's the proper way to set up the drop drop down options. the code I have is not working. please help. this is angular 18.

I have an array that is a computed signal, this is the definition:

selectableBoxeOptions(): Signal<BoxOptions[]|null>

these are all the boxeOptions you can select in a dropdown menu.

I have another computed signal and its call selectedBox. this is its definition:

selectedBox: Signal<Box | undefined>

BoxOptions object is not the same as the Box object.

selectedBox signal gets its value from the boxService.

I want to create a dropdown menu that the options are boxOptions in boxService.selectableBoxeOptions(). the display text for each option would be boxOption.model.name.

it should also have an option called "None", when its none, it means the selectedBox() is undefined or null.

when the dropdown loads, it should have one of the options selected already.

the selected option depends on what's selectedBox() which it gets its value from boxService.

if selectedBox() is undefined or null, the selected option would be "None".

if selectedBox() is not undefined or null, one of the other options should be selected.

this is how the selectedBox() is mapped to the boxOption in boxService.selectableBoxeOptions():

boxOption.device.serial === selectedBox()?.device.serial.

the user can choose a different option with the dropdown.

when the user selects the "None" option, it should call a method called boxService.deselectBox() which will make the selectedBox() undefined.

when the user selects other options, it should call a method called boxService.selectBox, and it would pass in the box.device.serial like this: boxService.selectBox(box.device.serial) which would set the selectedBox with a box.

I am not sure what's the proper way to set up the drop drop down options. the code I have is not working. please help. this is angular 18: (b-drop-down is just a web component)

<b-drop-down

label="Select A Box">

<select

[value]="selectedBox()?.device"

aria-describedby="boxes">

<option [selected]="selectedBox() == null" value="None">None</option>

@for (boxOption of mService.selectableBoxes(); track boxOption.device.serial) {

<option [selected]="boxOption.device.serial === selectedBox()?.device.serial" [value]="boxOption.device.serial">

{{ boxOption.model.name }}

</option>

}

</select>

</b-drop-down>
1
  • please share the minimal reproducible code, the code is more understandable than english, if possible a working example on stackblitz where the issue happens, steps to replicate and expected result from the stackblitz Commented Dec 10, 2024 at 5:13

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.