From ea4acaf9eb40fbc3e9f6750ea0e5ebd8c8d15fc7 Mon Sep 17 00:00:00 2001 From: robertIsaac Date: Tue, 19 Nov 2024 23:33:13 +0200 Subject: [PATCH] docs(core): Update linked-signal.md (#58756) fix multiple issues with the existing code 1. `shippingOptions` was accessed without `this.` which produces error in realtime 2. the logic in calculating of the item exist or not was not correct since it was comparing the object to the id 3. I'm not sure why, but step 3 fail without stating typing for LinkedSignal, so I added it PR Close #58756 --- adev/src/content/guide/signals/linked-signal.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adev/src/content/guide/signals/linked-signal.md b/adev/src/content/guide/signals/linked-signal.md index 0f721ec8041..d1ab6f18b05 100644 --- a/adev/src/content/guide/signals/linked-signal.md +++ b/adev/src/content/guide/signals/linked-signal.md @@ -63,13 +63,13 @@ In the example above, `selectedOption` always updates back to the first option w export class ShippingMethodPicker { shippingOptions: Signal = getShippingOptions(); - selectedOption = linkedSignal({ + selectedOption = linkedSignal({ // `selectedOption` is set to the `computation` result whenever this `source` changes. - source: shippingOptions, + source: this.shippingOptions, computation: (newOptions, previous) => { // If the newOptions contain the previously selected option, preserve that selection. // Otherwise, default to the first option. - return newOptions.find(opt => opt.id === previous?.value) ?? newOptions[0]; + return newOptions.find(opt => opt.id === previous?.value?.id) ?? newOptions[0]; } });