Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
Problem
Sometimes we want to sync signals from components to a service (or everywhere else I Assume)
@Component()
export class SomeComponent {
count = input(0)
double = computed(() => this.count() * 2)
}
@Injectable()
export class SomeService {
// Imagine I need the count/double here as well
}
Current solutions
- using
effect() to sync between the component and the service
effect(() => this.someService.double.set(this.double())
Obviously not the purpose of effects
- redesign the data-flow so the signal source will be on higher level
this is not always easy to implement, and in some cases even impossible, since we not always control everything
Proposed solution
Allow some new kind of utility to "Proxy" or "Sync" signals
class SomeService {
// will be updated from the component
count = syncedSignal<number>();
}
class SomeComponent {
someService = inject(SomeService)
count = input(0)
double = computed(() => this.count() * 2)
constructor() {
// "move" the signal to a service
syncSignal(this.count, this.someService.count)
}
}
- probably be one-way only
- worth exploring
connect from ngxtension
Alternatives considered
.
Which @angular/* package(s) are relevant/related to the feature request?
No response
Description
Problem
Sometimes we want to
syncsignals from components to a service (or everywhere else I Assume)Current solutions
effect()to sync between the component and the serviceObviously not the purpose of
effectsthis is not always easy to implement, and in some cases even impossible, since we not always control everything
Proposed solution
Allow some new kind of utility to "Proxy" or "Sync" signals
connectfrom ngxtensionAlternatives considered
.