From the course: Reactivity and Signals in Angular

Unlock this course with a free trial

Join today to access over 24,800 courses taught by industry experts.

Angular computed signals

Angular computed signals

- [Instructor] Sometimes we need to combine or manipulate signal values before we can use them in our application. Computed signals exist to handle state that is based off of another signal value, also called derived state. To instantiate a computed signal, we invoke the computed function with a callback that details the necessary calculation to return the derived state. Since signals are synchronous, we can perform any synchronous operation inside the callback function. We should never use asynchronous code inside of the callback because it does not provide consistent results. To leverage the power of a computed signal, we should always use the value of at least one signal inside the callback function. We can use values from one or more writeable signals or even other computed signals. We can narrow the type of the signal by providing a type. If our callback does not return the expected type, we will get a type error. Once the computed signal is instantiated, the only way to change…

Contents