I have an angular effect which I only want to be executed once.
But because it depends on other signals, I want it to wait first until all data is present. After that first execution, I don't want it to be triggered again.
I am looking for an elegant solution (not just some boolean to flip)
With Observables you could effectively use takeUntil or take(1). But what is the signal equivalent to this?
As mentioned in the angular doc:
Effects return an EffectRef that can be used to destroy them manually, via the .destroy() operation. This can also be combined with the manualCleanup option to create an effect that lasts until it is manually destroyed.
const effectRef = effect(()=>{
if(this.a() && this.b()){
console.log('ReadValue');
effectRef.destroy();
}
},{manualCleanup:true});
Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With