Do not read `window`, `document`, or `localStorage` directly during component construction, field initialization, or ordinary code that can run on the server. For one-time browser-only work, use `afterNextRender()`: ```ts import { Component, afterNextRender } from '@angular/core'; @Component({ selector: 'app-chart', template: '<div id="chart"></div>', }) export class ChartComponent { constructor() { afterNextRender(() => { const element = document.getElementById('chart'); const width = window...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-ssr --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Angular Ssr?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-ssr-df762da5)More formats (shields.io, HTML) on the badges page.
Do not read `window`, `document`, or `localStorage` directly during component construction, field initialization, or ordinary code that can run on the server. For one-time browser-only work, use `afterNextRender()`:
```ts
import { Component, afterNextRender } from '@angular/core';
@Component({
selector: 'app-chart',
template: '<div id="chart"></div>',
})
export class ChartComponent {
constructor() {
afterNextRender(() => {
const element = document.getElementById('chart');
const width = window.innerWidth;
// Initialize the browser-only chart here.
console.log(element, width);
});
}
}
```
`afterNextRender()` runs after Angular renders in the browser and does not execute as part of server rendering, so DOM APIs are safe inside that callback.
For recurring checks or callbacks, inject `PLATFORM_ID` and test `isPlatformBrowser()` before touching browser APIs:
```ts
import { isPlatformBrowser } from '@angular/common';
import { Component, inject, PLATFORM_ID } from '@angular/core';
export class ViewportComponent {
private readonly platformId = inject(PLATFORM_ID);
checkViewport(): void {
if (!isPlatformBrowser(this.platformId)) {
return;
}
const width = window.innerWidth;
// Recurring browser-only logic.
console.log(width);
}
}
```
Also clean up timers and event listeners when the component is destroyed. The important rule is that server-renderable component logic must not assume a browser global exists.
Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.
No comments yet. Be the first to comment!