First, I have never used lodash.clonedeep before but know JavaScript fairly well.
From my package,json file: "lodash.clonedeep": "4.5.0",
import { cloneDeep } from 'lodash.clonedeep';
editStart(): void {
this.oldData = cloneDeep(this.currentData);
this.editing = true;
}
Error: ERROR TypeError: lodash_clonedeep_1.cloneDeep is not a function
Help very MUCH appreciated since I'm out of options, have read and tried a lot of options. I have a workaround, using several objects, but want to avoid if possible.
Lodash is an excellent JavaScript utility library for those not knowing it yet. The cloneDeep method will iterate all levels of the original Object and recursively copying all properties found.
Adding Lodash To AngularWhat we also need is the type definitions to give us some nice strongly typed defintions inside Typescript. For that we need to install one more package. Note that we only add the type definitions as a dev dependency as it is not required at runtime, only while you are developing your project.
Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc. Lodash's modular methods are great for: Iterating arrays, objects, & strings. Manipulating & testing values.
A deep copy is a copy of all elements of the original object. Changes made to the original object will not be reflected in the copy. In this article, you will create deep copies of objects using the Lodash library.
Your import statement is incorrect.
You should either import the full library:
import * as _ from 'lodash';
...
let foo = _.cloneDeep(bar);
Or import just the cloneDeep function:
import * as cloneDeep from 'lodash/cloneDeep';
...
let foo = cloneDeep(bar);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With