Angular Tutorial 0/55 lessons ~6 min read Lesson 45

    Angular resource() Async Signals

    Angular resource() Async Signals in Advanced Angular: core concepts, worked examples, and practical guidance in one focused lesson.

    Course progress0%
    Focus
    5 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    Introduction

    resource() (Angular 19+) loads async data into signal-friendly status/value/error fields. It is the built-in pattern for request lifecycles without hand-rolling switchMap glue for simple cases. APIs continue to evolve — verify against your Angular minor version.

    Purpose of this lesson

    You will load a course by slug with resource() and render status in the template.

    Informative example

    Course resource by slug:

    typescript
    import { Component, inject, input, resource } from "@angular/core";
    import { HttpClient } from "@angular/common/http";
    import { firstValueFrom } from "rxjs";
    @Component({
    selector: "tlp-course-loader",
    template: `
    @if (courseResource.isLoading()) { <p>Loading…</p> }
    @else if (courseResource.error()) { <p>Failed</p> }
    @else {
    <h1>{{ courseResource.value()?.title }}</h1>
    }
    `,
    })
    export class CourseLoaderComponent {
    private http = inject(HttpClient);
    slug = input.required<string>();
    courseResource = resource({
    request: () => this.slug(),
    loader: async ({ request: slug }) =>
    firstValueFrom(this.http.get<{ title: string }>(`/api/courses/${slug}`)),
    });
    }

    Common mistakes

    • Treating resource() as a full replacement for complex RxJS streams — composition-heavy flows may still need Observables.
    • Ignoring error/loading branches in the template.

    Advanced interview questions

    Interview Prep

    Practice concise answers, then expand each card for the explanation.

    1 questions
    1IntermediateQuestionHow does resource() relate to signals?+

    Answer

    It exposes loading/error/value as signals so templates and computed values can react without manual Subject plumbing for simple request-per-input cases.
    Ready to mark this lesson complete?Track your journey across the entire course.