How to create a signal in Angular?
A signal is created using the signal() function from @angular/core. It takes an initial value. Example:
ts
import { signal } from '@angular/core';
const counter = signal(0);Now counter() is used to read the value, while set() or update() are used to change it:
ts
counter(); // get the value
counter.set(5); // set a new value
counter.update(v => v + 1); // change based on the previous oneShort Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.