Skip to content

docs: add new signals tutorial #62750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bencodezen
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • angular.dev application / infrastructure changes
  • Other... Please describe:

What is the current behavior?

Issue Number: N/A

There is no dedicated signals tutorial.

What is the new behavior?

There is now a dedicated signals tutorial! 🎉

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@bencodezen bencodezen added action: review The PR is still awaiting reviews from at least one requested reviewer area: docs Related to the documentation adev: preview labels Jul 22, 2025
@ngbot ngbot bot added this to the Backlog milestone Jul 22, 2025
Copy link

github-actions bot commented Jul 22, 2025

Deployed adev-preview for 5765670 to: https://ng-dev-previews-fw--pr-angular-angular-62750-adev-prev-9coiyqjg.web.app

Note: As new commits are pushed to this pull request, this link is updated after the preview is rebuilt.


// Query APIs to access child components
firstProduct = viewChild(ProductCard);
allProducts = viewChild.required(ProductCard, {read: ProductCard});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is toturial, so I will add that for me most dificult was using viewChild while reading ElementRef with genercis.
image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For context, this is a known issue #53894

@bencodezen bencodezen marked this pull request as ready for review July 24, 2025 14:13
@bencodezen bencodezen force-pushed the docs/signals-tutorial branch from 3bcbb8f to cbb6000 Compare July 28, 2025 11:26
@bencodezen bencodezen force-pushed the docs/signals-tutorial branch 3 times, most recently from cf0c40e to 11e9423 Compare July 28, 2025 14:03
@bencodezen bencodezen force-pushed the docs/signals-tutorial branch from 11e9423 to 5765670 Compare July 28, 2025 15:07
@jelbourn jelbourn self-requested a review July 28, 2025 15:58
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

got part of the way through, will spend some more time tomorrow


## How to use this tutorial

This tutorial assumes you understand Angular's core concepts. If you're new to Angular, read our [essentials guide](/essentials). For coding best practices, see the [Angular style guide](https://angular.dev/style-guide).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might leave out the reference to the style guide since there's not a whole lot that's related to signals specifically


<docs-step title="Configure OnPush change detection">
Update your component decorator to use `OnPush` change detection strategy. This is essential for components using signals as it optimizes performance by only checking for changes when signals update.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about only having a brief mention of OnPush at the end of this step instead of it being the very first thing?

My thinking is that developers don't really need to know any about it right away, it's more like
"You might notice the ChangeDetectionStrategy.OnPush throughout this tutorial. All you need to know is that this is a performance optimization for Angular components that use signals. Feel free to ignore this for the rest of the signals tutorial."


<docs-workflow>

<docs-step title="Import signal function and ChangeDetectionStrategy">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth having a distinct step for importing symbols? My thinking is that this is more of an aside while going through another step, e.g.

Add a `userStatus` signal to your component class that is initialized with a value of `'offline'` and has types for the common statuses (i.e., online, offline, and away). You can import `signal` from `'@angular/core'`.

<h1>User Dashboard</h1>
<div class="status-indicator" [class]="userStatus()">
<span class="status-dot"></span>
Status: {{ userStatus() }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like just showing the signal by itself is maybe a bit too little for a whole step. What do you think about combining this step with the next? For the sake of the tutorial, the second step can probably be simpler- instead of three buttons and three methods, you can just directly call userStatus.set in the template statement (<button (click)="userStatus.set('online')">Go online</button>)

<div class="user-profile">
<h1>User Dashboard</h1>
<div class="status-indicator offline">
<span class="status-dot"></span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the current preview on the PR, this status dot doesn't seem to show up?

isAvailable = computed(() => this.userStatus() === 'online');

statusColor = computed(() => {
switch (this.userStatus()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like having two different computed expressions that are both switch statements is a bit more repetitive than helpful. I could see having two computed expressions if one was more of a calculation, just to highlight the variety/flexibility of what you can do with computed

@@ -0,0 +1,77 @@
# Deriving state with linked signals

Now that you've learned [how to derive state with computed signals](/tutorials/signals/3-deriving-state-with-computed-signals), let's explore linked signals. Linked signals are a special type of signal that can be both read and written, while automatically deriving their value from other signals. Unlike computed signals which are read-only, linked signals can be updated directly while maintaining their reactive connection to source signals.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think of starting off by showing a linkedSignal and computed with the same expression, and then showing that linkedSignal is different because it can be directly updated?

@@ -0,0 +1,106 @@
# Managing async signals with Resources API
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we probably wouldn't want to use the term "async signals", since we want to be clear that signals are always synchronous. It's more that resource gives you a pattern for dealing with async data with signal APIs (i.e., the data is async, but the signals are always sync)

<docs-workflow>

<docs-step title="Import resource function and API">
Add `resource` to your existing imports and import the mock API function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would say "fake" instead of "mock"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
action: review The PR is still awaiting reviews from at least one requested reviewer adev: preview area: docs Related to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy