I'm facing an issue with Angular 2 that seems to be a common problem, but I haven't been able to find a solution yet. I've created a service that is called from another Component, which works fine.
The problem arises when I try to make an http POST request and encounter the following error:
[Exception: TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed on strict mode functions or the arguments objects for calls to them at Function.remoteFunction**
error screenshot
complete error screenshot
It appears that the error is occurring in the handleErrorObservable function, as the POST request is not being executed. When I check the network tab in Chrome, I don't see any POST call to the API.
Here's the code for my service:
import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions } from '@angular/http';
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import { User } from "./user";
import { HttpHeaders } from '@angular/common/http';
import { Headers } from '@angular/http';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class RegisterService {
usersUrl: 'http://localhost:8080/TrabajoPromocion/users/';
constructor(private http:Http) { }
addBookWithObservable( ): Observable<User> {
let body = JSON.stringify({
"fullname": "a",
"username": "h",
"password": "3",
"email": "33"
});
let headers = new Headers({ 'Content-Type': 'application/json' });
console.log('3');
let options = new RequestOptions({ headers: headers });
return this.http.post(this.usersUrl, body, options)
.map(this.extractData)
.catch(this.handleErrorObservable);
}
private extractData(res: Response) {
let body = res.json();
return body || {};
}
private handleErrorObservable (error: Response | any) {
console.error(error.message || error);
return Observable.throw(error.message || error);
}
}
Any assistance on resolving this issue would be greatly appreciated. Thank you.