Search code examples
angulartypescriptdialogsignalsangular-signals

NG0600: Writing to signals is not allowed in a `computed`


WHy am I getting the error: NG0600: Writing to signals is not allowed in a `computed`. yet I am using a writable signal?

Below is the code

dialog = signal(false)


openDialog(action: 'edit' | 'create') {
    this.dialog.update(action => action = !action)
    return action
  }

Solution

  • The syntax is wrong, it should be an arrow function which returns the new value, what is written is an assignment operation instead (action = !action).

    The equality written might be causing NG0600: Writing to signals is not allowed in a computed, because you are setting a value inside the update callback.

    Another big problem is, both the argument and the update argument of the arrow function are named action, so for better readability I renamed the first top argument to actionParam instead.

    dialog = signal(false)
    
    
    openDialog(actionParam: 'edit' | 'create') {
      this.dialog.update(action => !action)
    
      return actionParam;
    }