I
I
Ivan Stroykin2016-11-14 15:37:45
Angular
Ivan Stroykin, 2016-11-14 15:37:45

How to properly store data after a request in a service?

Good day,
I can not fully understand the services. The request to the backend passes once (as it should). But going to another page, and then returning back, the data cannot be collected correctly.
I output them to the "Data Tables" table via *ngFor. When the page is first opened, a request is made to the backend and everything is displayed and working well. But when you come to the page again, the data is visible, but on any action it disappears (for example, when trying to sort)
Component:

public dataTestServices: any;

    constructor(private servicesServices: ServicesService) {
    }

    ngOnInit() {
        this.servicesServices.getTestServices().subscribe(
            data => {
                this.dataTestServices = data.test_services;
            });
    }

service:
getTestServices() {
        return this.jsonApiService.getQuery('service/get_test');
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly, 2016-11-15
@StivinKing

There is a possibility that you are assigning a new (processed) array. The link to the previous array is lost, the trash can takes away all the data - that's all and disappears. You need to work with the original or assign a new array to the component again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question