Angular resources are not a good fit for Guards — CoPilot…
    Neura MarketNeura Market/CoPilot
    ChatGPTChatGPTClaudeClaudeGeminiGeminiCursorCursorGrokGrokPerplexityPerplexityCoPilotCoPilot
    DeepSeekDeepSeekStable DiffusionStable DiffusionMidjourneyMidjourney
    View All Directories
    OverviewRulesPromptsMCPsAgentsGamesBlogVideosGuidesCoursesCommunityPluginsTrending
    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:

    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):

    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
    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught megemma

    Five Gemma-4 models, one accelerator: what porting E2B 31B to AWS Inferentia2 taught me

    I ported the whole Gemma-4 family — E2B, E4B, 12B, 31B, and the 26B-A4B MoE — to run on...

    X
    xbill
    Hey DEV, I'm Tobore. Let's actually connect.community

    Hey DEV, I'm Tobore. Let's actually connect.

    Hey DEV, I'm Tobore. Let's actually connect. I've been on here for a while now, mostly writing and...

    L
    Laurina Ayarah
    I burned through thousands of AI tokens. Then a friend did it for freeai

    I burned through thousands of AI tokens. Then a friend did it for free

    (yep, kinda clickbait, just for the funsies 😊) At the beginning of the year, I relaunched my...

    P
    Paulo Henrique
    Claude might be saturating your machineai

    Claude might be saturating your machine

    My laptop was sitting idle with the fan at full tilt. Nothing was running that I knew of. The culprit...

    S
    Sidhant Panda
    Automated GitHub Code Reviews Using Google Geminigithubactions

    Automated GitHub Code Reviews Using Google Gemini

    I Built a Thing! TL;DR — Google Gemini-based Pull Request reviews and Issue Triaging for...

    D
    Darren "Dazbo" Lester
    What is an "agentic harness," actually?ai

    What is an "agentic harness," actually?

    I've been hearing the word "harness" thrown around a lot lately. I assumed it just meant "the IDE" or...

    T
    Tilde A. Thurium

    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.

    Neura Market

    Custom AI Systems & Services

    Our team of experienced AI builders will help build custom AI systems, workflows, and solutions for your business.

    Request custom work

    Ready-made automations for this

    Workflows from the Neura Market marketplace related to this CoPilot resource

    • Automatically Add New Google Sheets Entries as Resource Guru Resourcesmake · $2.99 · Related topic
    • Check VPS Resource Usage Every 15 Minutesn8n · $9.99 · Related topic
    • Automate Lesson Planning and Resource Creation for UK Teachersn8n · $14.99 · Related topic
    • Automate Learning Resource Recommendations from Hacker Newsn8n · $9.99 · Related topic
    Browse all workflows