Angular resources are not a good fit for Guards — CoPilot Blog
    Neura MarketNeura Market/CoPilot
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityCoPilotCoPilot
    DeepSeekDeepSeekStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsBlogVideosGuidesCoursesCommunityPluginsTrendingGenerate
    CoPilotBlogAngular resources are not a good fit for Guards
    Back to Blog
    Angular resources are not a good fit for Guards
    angular

    Angular resources are not a good fit for Guards

    Gérôme Grignon June 17, 2026
    0 views

    Angular 22 released a stable version of the Resource API, providing a complete API to query an API,...

    Angular 22 released a stable version of the Resource API, providing a complete API to query an API, now including loading/errors states builtin and some other features to improve our dev experience. One place in Angular apps where we need to make API calls are **Guards**... and **Resolvers**. They both block a current navigation to resolve their internal logic: - **For Guards**, the point is to prevent accessing the target route if falsy, used to prevent a user from accessing some route requiring to display data they are not allowed to (preventing UI errors as API calls will be rejected). - **For Resolvers**, the idea is to retrieve some data before hitting the target route, to pass it to the router and get it ready as soon as the component is rendered. They both block the navigation until their logic is resolved. For this reason they obviously return a `boolean`, a `Promise<boolean>`, or an `Observable<boolean>`. ## Why the Angular Resource API Fails in Guards Resources are part of the new Signals API, meant to provide a new reactive solution for Angular apps. But as being reactive, they do not synchronously return a value. When you create a Resource, its initial value is `undefined` while it immediately transitions into a loading state. Let's look at what happens if we try to use a Resource inside a Guard: ```typescript export const authGuard: CanActivateFn = () => { const authResource = httpResource<boolean>(() => ({ url: '/api/auth/status', })); // This returns the signal's current value synchronously // Which is `undefined` initially! return authResource.value() ?? false; }; ``` Because `.value()` is a Signal, reading it inside the Guard will synchronously return `undefined` (or whatever default value you provided). The Guard will immediately evaluate this to `false` and **cancel the navigation instantly**, without waiting for the API call to finish! To make this work, you would have to jump through hoops to convert the Resource's status into an Observable, wait for it to stop loading, and then emit the value. This defeats the entire purpose of the simple Router Guard API. ## The Right Approach: Observables and Promises Since Guards and Resolvers are meant to represent a single asynchronous event that blocks navigation, traditional Promises or RxJS Observables remain the perfect tool for the job. Instead of fighting against the reactive nature of Signals, stick to the `HttpClient` returning an `Observable` (or the native `fetch` API returning a `Promise`): ```typescript export const authGuard: CanActivateFn = () => { const http = inject(HttpClient); // An Observable cleanly blocks the Router until it completes or emits return http.get<boolean>('/api/auth/status'); }; ``` ## Conclusion The Resource API (`resource` and `httpResource`) is fantastic for components and services where you want to seamlessly bind async data to your templates while tracking loading and error states. However, **Guards and Resolvers are fundamentally about blocking a process until a single async event completes.** For these Router mechanisms, Promises and Observables are precisely designed to handle that kind of control flow. Keep your Guards simple, and save the Resource API for your UI's reactive data needs!

    Tags

    angularwebdev

    Comments

    More Blog

    View all
    Minimalist EKS: The Easy Waykubernetes

    Minimalist EKS: The Easy Way

    Amazon EKS manages the Kubernetes control plane, but you remain responsible for provisioning the...

    J
    Joaquin Menchaca
    Never forget to enter the Stern Grove lottery again!ai

    Never forget to enter the Stern Grove lottery again!

    Browser automation with Playwright, Python, GitHub Actions, and Entire to auto-enter San Francisco Stern Grove concert lotteries each week!

    L
    Lizzie Siegle
    A Free Screenshot Editor That Never Uploads Your Imagetypescript

    A Free Screenshot Editor That Never Uploads Your Image

    A free screenshot and image editor that runs entirely in your browser. Keeping every edit reversible and handling big phone photos, in plain TypeScript and Canvas2D.

    M
    Martin Stark
    I built a CLI to break my highlights out of Apple Booksshowdev

    I built a CLI to break my highlights out of Apple Books

    A macOS CLI + MCP server that exports Apple Books highlights to Markdown and gives AI assistants direct access to your reading notes.

    A
    Andrey Korchak
    A Developer's Guide to Agent Hooks in Antigravity CLIai

    A Developer's Guide to Agent Hooks in Antigravity CLI

    Motivation To be quite honest, "Hooks"—the shell commands we trigger at specific points...

    T
    Tanaike
    Tactical vs. Strategic Agentic AI Development — A Playbook for Developersagents

    Tactical vs. Strategic Agentic AI Development — A Playbook for Developers

    The Strategic Engineer: Why Writing Code Is No Longer Your Most Valuable Skill ...

    A
    Adewumi Saheed Adewale

    Stay up to date

    Get the latest CoPilot prompts, rules, and resources delivered to your inbox weekly.

    Neura Market LogoNeura Market

    Discover the best AI prompts, plugins, and resources for CoPilot and more.

    Content Types

    • Rules
    • Prompts
    • MCPs
    • Agents
    • Guides

    Platforms

    • ChatGPT Directory
    • Claude Directory
    • Gemini Directory
    • Cursor Directory
    • Grok Directory
    • Perplexity Directory
    • DeepSeek Directory
    • CoPilot Directory
    • Stable Diffusion Directory
    • Midjourney Directory
    • All Directories

    Resources

    • Blog
    • Documentation
    • Help Center
    • Marketplace

    Legal

    • Privacy Policy
    • Terms of Service

    © 2026 Neura Market. All rights reserved.

    |

    Not affiliated with any AI platform vendors.