import{ User}from'./user.model'
import{Injectable}from'@angular/core'
import{Http,Headers,Response}from"@angular/http";
import'rxjs/Rx';
import{Observable}from'rxjs';
@Injectable()
export classAuthService {
constructor(privatehttp: Http) {}
signup(user: User) {
constbody = JSON.stringify(user);
constheaders =newHeaders({'Content-Type':'application/json'});
return this.http.post('http://localhost:3000/user',body,{headers: headers})
.map((response: Response) => {returnresponse.json()})
.catch((error: Response) => Observable.throw(error.json()));
}
}
瀏覽器出現(xiàn)“TypeError: error.json is not a function”砰奕,但是http請求發(fā)送成功?
解決方法
檢查前后端的router的地址是否遺漏出錯