0

There are lot questions around this topic but I could not find a suitable solution. I am not able to see any error on the console, which is why its very confusing.

here is my service file code

   findVariantById(id: string):Observable<Evaluation[]>  {

    const endPoint = 'Evalution/Get'
    let params = new URLSearchParams();
    params.set('key', '1234'); //For example API key would come into picture
    params.set('id', id);
    params.set('format', 'json');
    params.set('callback', 'JSONP_CALLBACK');
    // this much code gets called but nothing on Network tab. 
    return this.http.get(this.apiUrl + endPoint, { search: params })
         .map<Evaluation[]>(this.extractData)
        .catch<Evaluation[]>(this.handleError);
} 

Here is my component file code which calls the service

    evaluation(id: string) {
        this.searchService.findVariantById(id)
            .subscribe(
            evaluations => this.evaluations = evaluations,
            error => this.errorMessage = <any>error);
    }        

and Model

  export interface Evaluation {
    QuestionId: string;
    QuestionText: string;
    questionResponse: Array<Object>
  }

I have included appropriate dependencies for the same

   import { Observable } from 'rxjs/Observable';
   import 'rxjs/add/operator/map';
   import 'rxjs/add/operator/catch';
    import 'rxjs/add/operator/toPromise';

I am using "@angular/core": "~2.2.1", and "rxjs": "5.0.0-beta.12". Any kind of help is highly appreciated. Thank you

Update: After switching to Angular:4.0.1, Http.Get and Post gave error as

Supplied parameters do not match any signature of call target.

So I made following changes. And it worked perfectly.

  return this.http.get(this.apiUrl + endPoint, { search: params })
        .map(this.extractData)
        .catch(this.handleError); 
3
  • can you also add whats the problem you are facing ? Commented Mar 16, 2017 at 9:28
  • 1
    Do you see a network request going out (in the devtools network tab)? Commented Mar 16, 2017 at 9:29
  • I am not able to see the request on Network tab. Its like a ghost request. The problem is that I am not able to perform any HTTP get on my angular2 website. and no error visible on console. Commented Mar 16, 2017 at 11:59

1 Answer 1

3

This error was due to a Fake Backend Provider which Mocks HTTP requests.

I have used Fake Backend Provider to perform Login and registration, as per following tutorial.
More info on: http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial

By removing its dependencies from app.module.ts,it solved my problem.

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

1 Comment

Thank you for this tip - I was racking my brain on this until your simple tip reminded me I had a mock db going as well.

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.