blog/angular-signal-inputs #19
Replies: 3 comments 5 replies
-
|
It's a tad frustrating that effects have to run (at least once) unlike a setter. I'm guessing there's no elegant way around this right? |
Beta Was this translation helpful? Give feedback.
-
|
Do you have an example on how to test a component with a required input signal, and some computed values depending on it? |
Beta Was this translation helpful? Give feedback.
-
|
I have a slightly different use case which I am not sure how I should solve. I am using an input signal to bind to a property from the parent component, I also have a local writeable signal for managing the state of a checkbox. The checkbox should be deselected when a new dialogue loads. dialogue = input.required<Dialogue>();
showTranslation = signal(false);If the user selects a new route the component is reused, it is not destroyed, the dialogue signal will be updated but showTranslation is not reset. I have two solutions, neither of which feel right. // Solution #1 simple but is this really the correct approach in a new signal based world?
ngOnChanges(changes: SimpleChanges) {
if (changes['dialogue']) {
this.showTranslation.set(false);
}
}Or... // Solution #2 works ok but seems complicated and messy.
subscription!: Subscription;
dialogue$ = toObservable(this.dialogue);
ngOnInit() {
const dialogue$ = toObservable(this.dialogue);
this.subscription = this.dialogue$.subscribe(val => this.showTranslation.set(false));
}
ngOnDestroy() {
this.subscription.unsubscribe();
}I also looked at using effect() or toSignal()/toObservable(), but neither of these allow me to also use the signal set() function to update the state of showTranslation. Is there a better way to handle this? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
blog/angular-signal-inputs
Revolutionize Your Angular Components with the brand new Reactive Signal Inputs.
https://angularexperts.io/blog/angular-signal-inputs
Beta Was this translation helpful? Give feedback.
All reactions