skip to content
Alvin Lucillo

Readonly signal

/ 1 min read

If you have a reusable component/service, there’ll be instance that you want your reactive values to not be modifiable. That’s where readonly signals are useful.

In the example below, message is a readonly signal. It has a type Signal<string>. On the other hand, you have writeable signal message1 with type WritableSignal<string>. With the former, you won’t be able to use set.

@Injectable({
	providedIn: "root",
})
export class TestService {
	#messageSignal = signal("");
	message = this.#messageSignal.asReadonly();
	message1 = signal("");
}