In this example, we're creating a simple Angular standalone component that fetches a list of users from an API using HttpClient.get() and displays them in the template using RxJS and Angular's async pipe:
app.component.ts
user.ts
main.ts
src/app.component.ts
src/user.ts
src/main.ts
Output
How it works
1
Get Users
The following line creates the users$ observable that sends an HTTP GET request to fetch the list of users:
2
async pipe & @forAngular v.17
The async pipe subscribes to users$, and the data is automatically rendered when available.
The template uses a @for loop to asynchronously iterate over users$.
The async pipe automatically subscribes to the Observable and updates the DOM when the data arrives.
The track by user.id ensures efficient DOM updates by uniquely identifying each user using their id.