Issue
I have this code
this.items.mutate(products => this.sourceData.getData().forEach(item => products.push(item)));
updating the library from Angular 16 to Angular 17 I need to remove 'mutate' using 'update' or 'set', but I don't know how to do it.
I should change products.push(item)
-> [...products, item]
but I don't know how to do it with the forEach
.
Solution
In v17 signals enforce immutability, therefor you need to return a new instance of your array. Using a spread operator is a good option:
this.items.update(products => {
return [...products, ...this.sourceData.getData()]
})
Answered By - Matthieu Riegler
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.