platform-access-di

Applies dependency-injection patterns for window, document, and platform checks in Angular code.

1|Updated Jan 14, 2024
One-click install
npx skills add https://github.com/Eyhenij/rt-tools --skill platform-access-di-eyhenij
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: platform-access-di
Source: https://github.com/Eyhenij/rt-tools/tree/main/.claude/skills/platform-access-di
Command: npx skills add https://github.com/Eyhenij/rt-tools --skill platform-access-di-eyhenij

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @rt-tools/core, @angular/common, @angular/core.

What problem does it solve? Angular code that touches browser globals like window or document breaks under server-side rendering and becomes untestable. This Skill provides the established DI-based pattern for accessing these globals safely through tokens and services. ## Core Features & Use Cases - Token-based injection: Inject WINDOW, DOCUMENT, and PlatformService instead of referencing globals directly in components, services, and directives. - Typed global access: Cast the WINDOW token to Window & typeof globalThis with an explanatory comment when constructors like IntersectionObserver or ResizeObserver are needed. - Pure function support: Pass the window object as a parameter into *.logic.ts and *.util.ts functions that have no DI context. - Render-safe DOM work: Guard environment checks with PlatformService.isPlatformBrowser and defer DOM initialization with afterNextRender. - Use Case: When adding Google Maps loading to a component, inject WINDOW, cast it with a comment, pass it into a pure mapsReady function, and skip execution on non-browser platforms. ## Quick Start Apply the platform-access pattern to inject WINDOW and PlatformService instead of touching window or document directly in this Angular service.

Frequently Asked Questions about platform-access-di

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I access window in an Angular service with SSR?

Inject the WINDOW token from @rt-tools/core instead of referencing the global window directly. This keeps the service testable and prevents crashes during server-side rendering where window does not exist.

How to check if code runs in the browser in Angular?

Inject PlatformService and check its isPlatformBrowser property before running browser-only logic. Avoid typeof window !== 'undefined' checks, which only accidentally detect the environment and bypass the DI abstraction.

Why does Window type not include IntersectionObserver or ResizeObserver?

The Window interface omits global constructors and namespaces declared on globalThis. Cast the injected WINDOW token to Window & typeof globalThis and add a comment explaining the narrowing, since the token returns the same object.

Can pure utility functions use Angular dependency injection?

No, *.logic.ts and *.util.ts files have no DI context. Pass the window object as a function parameter, and let the calling component or service inject the WINDOW token and supply it.

When should DOM manipulation run in an Angular component?

DOM work that depends on rendered output must run inside afterNextRender, not in constructors or field initializers. Combine this with a PlatformService browser check so the code is skipped during server-side rendering.