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:

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

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

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay