0

I have an angular application which has a form. I have my backend APIs written in Graphql. I am fetching data using Apollo Angular library to populate the fields within the form (which uses ngModel for binding) for my application user. I have given the user the ability to go ahead and edit the fields within the form. I, however, am getting the following error while changing the values of the the fields. From what I have read it is happening because the cache values in apollo angular are immutable. How do I still allow the user to change the fields within the form? Is there a proper solution or a workaround available for such issues?

core.js:4197 ERROR TypeError: Cannot assign to read only property 'name' of object '[object Object]'

Thank you.

Neha Soni
  • 1
  • 2
  • Could you please shared your code. We can't possibly know what's going on without your code. – Nicolas Oct 07 '20 at 22:54
  • `ngModel` will change the value of the property when it changes, if you assign it as `readonly`, when the `ngModel` sets the value, he can't, because it's `readonly`. Did you understand? – Jorge Mussato Oct 07 '20 at 23:01
  • @JorgeMussato Yes, I do understand. So, Is there a way to not have the cache value as readonly and change the field values? – Neha Soni Oct 07 '20 at 23:10
  • yes if you create another duplicated object. I would recommend you to use the Reactive Forms instead. https://angular.io/guide/reactive-forms. – Jorge Mussato Oct 07 '20 at 23:18
  • @JorgeMussato Perfect! That answered my question. Thanks a lot! – Neha Soni Oct 08 '20 at 20:00

0 Answers0