Skip to content

docs: document arrow function template expressions in developer skill - #71395

Open
diegoinost02 wants to merge 1 commit into
angular:mainfrom
diegoinost02:docs/skill-arrow-functions
Open

diegoinost02 wants to merge 1 commit into
angular:mainfrom
diegoinost02:docs/skill-arrow-functions

Conversation

@diegoinost02

Copy link
Copy Markdown
Contributor

Template expressions support arrow functions with an expression body (e.g. items().filter((i) => i.active)), which was not documented anywhere in the angular-developer skill. Block-body arrow functions remain unsupported, and a pipe cannot be used inside an arrow function's body.

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?

components.md doesn't mention that template expressions support arrow functions.

Issue Number: N/A

What is the new behavior?

Adds an "Arrow Functions in Template Expressions" subsection.

Does this PR introduce a breaking change?

  • Yes
  • No

Template expressions support arrow functions with an expression body
(e.g. items().filter((i) => i.active)), which was not documented
anywhere in the angular-developer skill. Block-body arrow functions
remain unsupported, and a pipe cannot be used inside an arrow
function's body.
@pullapprove
pullapprove Bot requested a review from kirjs October 16, 2026 16:31
@angular-robot angular-robot Bot added the area: docs Related to the documentation label Oct 16, 2026
@ngbot ngbot Bot added this to the Backlog milestone Oct 16, 2026
callbacks:

```html
{{ items().filter((i) => i.active).length }}

@JeanMeche JeanMeche Oct 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This def' not a great example for inline arrow functions (it would run on every CD cycle).

The best use-case is a signal update in an event listener.

{{ items().filter((i) => i.active).length }}
```

Arrow functions with a block body (`() => { ... }`) are not supported. A pipe cannot be used

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I think the most common mistake here (especially coming from React) is (click)="() => save()", which never calls save. The compiler only reports it as a warning (NG8111), so the build still passes. Maybe we can keep this paragraph focused on what changes the code the agent writes:

Suggested change
Arrow functions with a block body (`() => { ... }`) are not supported. A pipe cannot be used
Arrow functions must have an expression body, such as `(c) => c + 1`. In event bindings, call the
method directly, `(click)="save()"`, because an arrow function like `(click)="() => save()"` is
never invoked.

I'm not sure the pipe part adds much for an agent, so I left it out, but let's see what others think.

callbacks:

```html
{{ items().filter((i) => i.active).length }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure this is a good example, it's derived state in the template, so filter runs on every check even if items didn't change. The skill and our best practices recommend computed for this, so I think the agent would learn the opposite.

I think we can replace it with the following :

Suggested change
{{ items().filter((i) => i.active).length }}
```html
<button (click)="count.update((c) => c + 1)">Increment</button>
```
For derived values such as a filtered list, use a `computed` signal in the component instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: docs Related to the documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants