You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
I have created a "multi select" component where a user can select any number of choices from a given list. This list is added to the component with an input signal. The selected options are stored in a WritableSignal as the user selects them. If the list of choices is updated from outside the component by the template embedding it the list of selected values need to be reset. I have not found a good way of doing this with signals whereas this was easily possible with ngOnChanges and the old @Input decorator.
The documentation warns against writing to signals in an effect so using an effect to do this does not seem like the best idea.
@Component({selector: 'app-multi-select-group',templateUrl: './multi-select-group.component.html',})exportclassMultiSelectGroupComponent{// issue is herepublicoptions=input<Array<MultiSelectGroupOption>>([]);// <- when this changes selectedItems needs to be resetpublicselectedItems=signal<Array<MultiSelectGroupOption>>([]);
@Output()// ignore that I'm using the old API here Webstorm cannot deal with output signals properly yetpublicselectionChange=newEventEmitter<Array<MultiSelectGroupOption>>();publicconstructor(){effect(()=>{this.selectionChange.emit(this.selectedItems());});}publicselectItem(item: MultiSelectGroupOption): void{this.selectedItems.set([...selectedItems,item]);}}
Proposed solution
Add an option to the input signal to specify a function that can do writes to other signals once the component input changes.
Alternatives considered
The alternative I could think of would be a adding a way to completely reset a component once a specific input signal changes.
The text was updated successfully, but these errors were encountered:
Which @angular/* package(s) are relevant/related to the feature request?
core
Description
I have created a "multi select" component where a user can select any number of choices from a given list. This list is added to the component with an input signal. The selected options are stored in a WritableSignal as the user selects them. If the list of choices is updated from outside the component by the template embedding it the list of selected values need to be reset. I have not found a good way of doing this with signals whereas this was easily possible with ngOnChanges and the old
@Input
decorator.The documentation warns against writing to signals in an effect so using an effect to do this does not seem like the best idea.
Proposed solution
Add an option to the input signal to specify a function that can do writes to other signals once the component input changes.
Alternatives considered
The alternative I could think of would be a adding a way to completely reset a component once a specific input signal changes.
The text was updated successfully, but these errors were encountered: