D
D
dima-gr2017-01-27 13:25:53
Angular
dima-gr, 2017-01-27 13:25:53

How to get rid of the error "Property 'data' does not exist on type 'Subscribers[]'"?

Hello.
There is json

{
"count":"404875",
"data":[{
 ... 
}]
}

In the service I receive a response from the server
getSubscribers(page:Number, pageSize:Number): Observable<Subscribers[]> {
        return this.http.get(this._subscribers +'/'+page+'/'+pageSize)
            .map(this.extractData)
            .catch(this.handleError)
    }

    private extractData(res: Response) {
        let body = res.json();
        return body;
    }

in component i am trying to process this json
getSubscribers(page = 1){
        this.subscribersService.getSubscribers(page, this.pageSize)
            .subscribe(
                data => {
                    this.subscribers = data.data,
                    this.count = data.count,
                    this.p = page
                },
                error => this.errorMessage = <any>error
            )
    }

And everything works. The data is displayed correctly and everything works fine, but when you start npm, errors pop up in the console
app/components/subscribers/index.component.ts(32,45): error TS2339: Property 'data' does not exist on type 'Subscribers[]'.
app/components/subscribers/index.component.ts(33,39): error TS2339: Property 'count' does not exist on type 'Subscribers[]'.

I understand that it says here that the given object does not have these properties. I recently started learning angular and don't understand how to deal with it yet. I would be very grateful for hints or help where or what I did wrong.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question