-
Notifications
You must be signed in to change notification settings - Fork 26.5k
Open
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signals
Milestone
Description
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 effect
s
- 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
.
e-oz, khalilou88, Harpush, Avcharov, ncamera and 5 moree-oz and zygariosmichael-small
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimeIssues related to the framework runtimecross-cutting: signals