← All notes

@if and @for are Angular's built-in template control flow

Answer: Angular templates support control flow blocks that show, hide, or repeat elements. @if displays its content when the condition expression is truthy. You can provide any number of @else if blocks and a singular @else block. @if can also save the condition result into a variable for reuse inside the block.

Repeating content

The @for block loops through a collection and repeatedly renders the block's content. The collection can be any JavaScript iterable. Angular has extra performance optimizations for Array values. @for does not support flow-modifying statements such as JavaScript continue or break.

The track expression lets Angular keep a relationship between your data and the DOM nodes on the page, so it can run the minimum DOM operations when the data changes. Prefer a property that uniquely identifies each item, often id or uuid.

In source

The conditional instruction is the runtime building block for built-in if and switch. It adds and removes the views selected by a conditional expression. An LContainer is created for a root node of control flow such as @if or @switch. Another LContainer represents a branch of control flow such as @else or @case.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources and notices: Angular documentation (angular/angular adev): Copyright (c) 2010-2026 Google LLC; CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Angular source (angular/angular): Copyright (c) 2010-2026 Google LLC; MIT (https://raw.githubusercontent.com/angular/angular/main/LICENSE). Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Angular docs, CC BY 4.0 text (angular/angular adev footer); Angular source, MIT (angular/angular). Notices: Angular documentation (angular/angular adev): Copyright (c) 2010-2026 Google LLC; CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Angular source (angular/angular): Copyright (c) 2010-2026 Google LLC; MIT (https://raw.githubusercontent.com/angular/angular/main/LICENSE).

Cite this

Permanent ID: iil:note:wmp15me4

iinventedlight. 2026. "Angular @if and @for are built-in template control flow." iinventedlight Library, iil:note:wmp15me4, version of 2026-11-11. https://iinventedlight.com/library/notes/angular-control-flow/. License: CC-BY-4.0.

@misc{iil_note_wmp15me4,
  author = {{iinventedlight}},
  title = {{Angular @if and @for are built-in template control flow}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-11},
  url = {https://iinventedlight.com/library/notes/angular-control-flow/},
  note = {Permanent ID iil:note:wmp15me4. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/angular-control-flow.md.