Getting Post angular 2 toPromise HTTP

Viewed 2103

Hello I need to get some response after posting json object, using toPromise, its my code, respond is undefined:

export class ApiStorage{
constructor( @Inject(Http) private http: Http ){}
    rs(){
    this.http.post('http://0.0.0.0:80/student/outbound', this.json, headers)
            .toPromise()
            .then(response => {
                respond = JSON.stringify(response);
                return respond; //<- edited
            })
            .catch((error: any) => {
            ...
                });
    }
}

then when in main component I use

send(){
    respondJSON = apistorage.rs();
    console.log(respondJSON);
    }

respondJSON is undefined

1 Answers
Related