I have this array:
productCarts: ProductModel[] = [];
And when I call this method in ngInit I have error Cannot read property 'length' of null:
addProductFromLocalStorage() {
if (this.productCarts.length == 0) {
this.productCarts = this.fromLocalStorage;
}
}
Solution: My local storage return the null value and I hade exception.
this.fromLocalStorageisnull