1

In my service I execute an http call and return the response as Observable

doQuery ( query: String ) : Observable<any> {
    return this.http.request(queryURL) ;   
}

And in a component I subscribe

this.service
    .doQuery(this.query)
    .subscribe((res: any) => {
        console.log ("Res");
        console.log(res);
    });

Doing this actually works; I can see in the console the dump of a Response object

My problem came when I want to return from the service the response alread mapped as json.

I trying to do tyhis

return this.http.request(queryURL).map((res: any) => res.json());

But at runtime I got an obscure javascript error (this is coming from Zone.js to be precise)

Error: Permission denied to access property "rejection"

I've already tried to change the return type from Observable<any> to Observable<any[]>, as seen on a book, but without success.

UPDATE : Actually I resolved adding into the service file this import 'rxjs/Rx';

What am I doing wrong? Why is this import needed ? Isn't a way to import Rxjs' map operator?

1
  • 2
    If you found an answer to your question, please add your own reply with the solution for other people to find. Commented Nov 25, 2016 at 14:10

1 Answer 1

-1

In this specific situation, i resolved adding the import

import `rxjs/Rx`;

But in the 99% of other times this happened again to me, this error was due to a missing declaration of one service in the providers array in the @NgModule

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.