DEV Community

Nhan Nguyen
Nhan Nguyen

Posted on

4

Angular Signals update function

We have a signal value with an object type and want to update one or some of that object's values.

In this case, we can use the Angular Signals update function and JavaScript spread syntax:

this.user.update((user) => ({ ...user, fistName: "First name updated!" }));
// or
this.user.update((user) => ({ ...user, fistName: "First name updated!", lastName: "Last name updated!" }));
// or
this.user.update((user) => ({ ...user, ...this.curUser }));
Enter fullscreen mode Exit fullscreen mode

A complete example is here 👉 https://stackblitz.com/edit/stackblitz-starters-dprcl3?file=src%2Fmain.ts


I hope you found it helpful. Thanks for reading. 🙏

Let's get connected! You can find me on:

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (2)

Collapse
 
artydev profile image
artydev

Thank you

Collapse
 
nhannguyendevjs profile image
Nhan Nguyen

You are welcome!

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay