-
Notifications
You must be signed in to change notification settings - Fork 27.1k
NG0600: Error thrown when updating signals inside not computed functions #60247
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Description
Which @angular/* package(s) are the source of the bug?
core
Is this a regression?
No
Description
The error NG0600: Writing to signals is not allowed in a computed is incorrectly triggered even when the signal update occurs outside a computed function.
In the following example, a function is executed within the template, where it updates a signal. However, this triggers the NG0600 error unexpectedly.
https://stackblitz.com/edit/stackblitz-ng0600-error-polygon?file=src%2Fmain.ts
import { Component, signal } from '@angular/core';
import { bootstrapApplication } from '@angular/platform-browser';
@Component({
selector: 'app-root',
template: `
<p>NG0600 occurring with common functions</p>
<button [disabled]="disabled()">Test</button>
{{fnInTemplate()}}
`,
})
export class App {
protected readonly disabled = signal(true);
protected fnInTemplate() {
this.disabled.update((v) => !v);
}
}
bootstrapApplication(App);This issue may be related to the #60143
Please provide a link to a minimal reproduction of the bug
https://stackblitz.com/edit/stackblitz-ng0600-error-polygon?file=src%2Fmain.ts
Please provide the exception or error you saw
NG0600: Writing to signals is not allowed in a computed
Workaround
If the signal.set function is executed inside a setTimeout or any kind of ngZone escape, it works as expected.
Please provide the environment you discovered this bug in (run ng version)
Angular CLI: 19.0.7
Node: 18.20.3
Package Manager: npm 10.2.3
OS: linux x64
Angular: 19.0.6
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, router
Package Version
------------------------------------------------------
@angular-devkit/architect 0.1900.7
@angular-devkit/core 19.0.7
@angular-devkit/schematics 19.0.7
@angular/build 19.0.7
@angular/cli 19.0.7
@schematics/angular 19.0.7
rxjs 7.8.1
typescript 5.6.3
zone.js 0.15.0
Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels