Angular State Management
ASecurityKeep the writable signal private, then expose its readonly view: ```ts import { Injectable, signal } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class CounterService { private readonly countState = signal(0); readonly count = this.countState.asReadonly(); increment(): void { this.countState.update(value => value + 1); } reset(): void { this.countState.set(0); } } ``` Consume it in a component: ```ts @Component({ template: ` <p>{{ counter.count() }}</p> <button (click)="co...
- 584 stars
- 0 votes
- 0 copies
- 1 view
- Added September 5, 2026
Works with
Security analysis
100/100Pro scans all 18 files and shows the line behind each finding
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-state-management --agent claude-codeAre you the author of Angular State Management?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-state-management-68ddc081)Keep the writable signal private, then expose its readonly view:
```ts
import { Injectable, signal } from '@angular/core';
@Injectable({ providedIn: 'root' })
export class CounterService {
private readonly countState = signal(0);
readonly count = this.countState.asReadonly();
increment(): void {
this.countState.update(value => value + 1);
}
reset(): void {
this.countState.set(0);
}
}
```
Consume it in a component:
```ts
@Component({
template: `
<p>{{ counter.count() }}</p>
<button (click)="counter.increment()">Increment</button>
`,
})
export class CounterComponent {
constructor(public readonly counter: CounterService) {}
}
```
`count()` can be read publicly, but callers cannot call `.set()` or `.update()` on it. Only the service changes the internal state. Avoid updating signals inside `effect()`; use effects only for side effects.
Files in this skill
- eval-1.baseline.md
- eval-1.with-skill.md
- eval-2.baseline.md
- eval-2.with-skill.md
- eval-3.baseline.md
- eval-3.with-skill.md
- eval-4.baseline.md
- eval-4.with-skill.md
- eval-5.baseline.md
- eval-5.with-skill.md
- eval-6.baseline.md
- eval-6.with-skill.md
- trigger-1.md
- trigger-2.md
- trigger-3.md
- trigger-4.md
- trigger-5.md
Attribution
Related skills
View all in development →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.