In my angular application, I have stored categories in a service. In my component I'm removing the first categories from the array and displaying it. The first category is "ALL", and I don't want to display that.
So when I edit the createCategories
array in component, the service data also gets changed. How can I keep the original data in service and just manipulate the data in the component?
Below is the code in the component:
this.createCategories = this.myServ.getCategories();
this.createCategories.splice(0, 1);
The service getCategories
method:
public getCategories() {
return this.categories;
}
Now what is happening is every time we call the component one category is removed from the array and also in the service.
Please guide.