最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

angular - NG0600: Writing to signals is not allowed in a `computed` - Stack Overflow

programmeradmin0浏览0评论

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
  }

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
  }
Share Improve this question edited Feb 6 at 8:28 Naren Murali 56.8k5 gold badges40 silver badges71 bronze badges asked Feb 6 at 6:51 kibetkibet 3793 silver badges10 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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;
}
发布评论

评论列表(0)

  1. 暂无评论