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)="co...
Scanned 9/5/2026
Install to Claude Code
npx -y skills add HoangNguyen0403/agent-skills-standard --skill angular-state-management --agent claude-codeInstalls into .claude/skills of the current project.
Are you the author of Angular State Management?
Add the live security badge to your README — it updates automatically with every re-scan.
[](https://www.skillsdirectory.com/skills/hoangnguyen0403-angular-state-management-68ddc081)More formats (shields.io, HTML) on the badges page.
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.
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!