Make an Angular Signal Readonly

Tomasz Ducin
InstructorTomasz Ducin
Share this video with your friends

Social Share Links

Send Tweet
Published 8 months ago
Updated a month ago

Read-only signals in Angular let you share values between components safely. They update automatically when the original signal changes.

They can't be changed directly, like computed signals. And, they are useful in services.

[00:00] Create a new property and call the as read only method on an existing signal. A read only signal holds the very same value as the original signal. And whenever the original signal value gets updated, read only also gets updated. Let's display the value of our read only [00:20] signal here in the handle click. So we're going to read the value of the read only items. So whenever we click log items, we will see what are the values. And whenever we update the value of our signal and we log once again, we will see that both the [00:40] original signal items and its read only version both get updated. The whole point of a read only signal, as the name suggests, is that we should not be able to modify the value. So neither the set nor the update method exist on a read only signal. However, if we take just an ordinary signal, [01:00] which appears to be a writable signal, then both the set method and the update method are present. A computed signal shares the same type as read only signals, so the main signal type, which doesn't have the state and update method. That's because the value of a computed [01:19] signal is a computation depending on another signal. In this case, last item depends on these dot items. Changing a value of a computed signal would be illogical, and therefore this dot last item dot set and update, they don't exist. Read only signals are not very useful within [01:39] components, but they are super useful within services.

egghead
egghead
~ 29 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today