In Angular, both Signals and Observables can be used to react to data changes. Which statement best describes how Signals differ from Observables in terms of update behavior?
Think about how each handles the timing of updates and whether they keep the last value accessible.
Signals in Angular update synchronously and always hold the latest value, making them easy to read directly. Observables emit values asynchronously and do not cache the last value unless operators like shareReplay are used.
Consider an Angular component that displays a counter value. The counter is provided as a Signal in one version and as an Observable in another. What difference in rendering behavior will you observe?
Think about how Angular templates handle Signals and Observables differently.
Signals can be read directly in templates and update synchronously, so the view updates immediately. Observables require the async pipe or manual subscription to trigger view updates.
Which option shows the correct way to create a Signal and an Observable that emit numbers starting from 0 every second?
Remember the Angular Signal creation function and RxJS interval syntax.
Signals are created with the signal function passing an initial value. Observables emitting values at intervals use RxJS's interval function with the interval in milliseconds.
Given this Angular component code snippet, why does the view not update when count$ emits new values?
count$ = interval(1000);
ngOnInit() {
this.count$.subscribe(value => {
this.currentCount = value;
});
}Think about Angular's change detection and how it tracks changes to variables.
Angular's change detection does not automatically track changes to plain variables like currentCount. Using Signals or triggering change detection manually is needed to update the view.
Consider this Angular component snippet:
const countSignal = signal(0);
const countObservable = interval(1000);
countObservable.subscribe(value => {
countSignal.set(value);
});
console.log(countSignal());What will be logged immediately after this code runs?
Think about when the Observable emits its first value relative to the console.log call.
The Observable interval(1000) emits its first value after 1 second asynchronously. The console.log runs immediately, so the Signal still holds its initial value 0.