Angular 4: HTTP doesn't sent POST data -
i trying make web application , want test http functions, have problem.
for example: have this:
import { injectable } '@angular/core'; import { headers, requestoptions, http } '@angular/http'; import {observable} 'rxjs/rx'; // import rxjs required methods import 'rxjs/add/operator/map'; import 'rxjs/add/operator/catch'; @injectable() export class userservice { constructor(private http: http) { } create(data: object): observable<any> { let headers = new headers({'content-type': 'application/x-www-form-urlencoded'}), options = new requestoptions({ headers: headers}); return this.http.post('http://localhost:8000/api/signin', {headers:headers}).map((res) => { res.json(); alert('ma-ta'); }).catch((error:any) => observable.throw(error.message)); } } the function called, verified, http.post doesn't work, mean, not sent data link, in console have nothing @ network, , receive this:
12:01:18.779 object { _isscalar: false, source: object, operator: object } 1 main.bundle.js:444:9 it's kinda empty, things don't need, error information or something. can me ?
you sending empty post. setting headers (which isn't needed) , not sending data through post request. please see below:
create(data: object): observable<any> { let url: string = 'http://localhost:8000/api/signin'; return this.http.post(url, data) .map((res: response) => res.json()) .catch((error:any) => observable.throw(error.message)); } also remember import following:
import { injectable } '@angular/core'; import { http, response } '@angular/http'; import { observable } 'rxjs/observable'; import 'rxjs/rx';
Comments
Post a Comment