0

I am trying to use Http in angular2/ionic2.

My service code is

    getImageQuestionsFromServer(id:string){
    let questions = this._http.get(`http://abcd.com/cbsapp/package_content/${id}/image_questions.json`).map((res: Response) => res.json());
    return questions;
  }

My component code is

this._userDataService.getImageQuestionsFromServer(this.passedPackage.id)
            .subscribe(
            (data) => console.log(data.status),
            (err) => console.log(err)
            )

I dont know how to check the Http status codes inside my component. Please help.

1 Answer 1

1

Service method:

getImageQuestionsFromServer(id:string){
  return this._http.get(`http://abcd.com/cbsapp/package_content/${id}/image_questions.json`);
}

Component method:

this._userDataService.getImageQuestionsFromServer(this.passedPackage.id)
            .subscribe(
            (response) => {
              let status = response.status
              let data = response.json();
            },
            (err) => console.log(err)
            );
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.