Current behavior
I'm getting the following exception when I pass up an observable over 2 methods:
TypeError: Converting circular structure to JSON
at JSON.stringify (<anonymous>)
at HttpRequest.serializeBody (http.js:916)
at Observable._subscribe (http.js:2196)
at Observable._trySubscribe (Observable.js:172)
at Observable.subscribe (Observable.js:160)
at Object.subscribeToResult (subscribeToResult.js:23)
at MergeMapSubscriber._innerSub (mergeMap.js:132)
at MergeMapSubscriber._tryNext (mergeMap.js:129)
at MergeMapSubscriber._next (mergeMap.js:112)
at MergeMapSubscriber.Subscriber.next (Subscriber.js:90)
If I call the method post2
(see below) directly in the login
function then everything works and I see the success message.
Expected behavior
No exception should occur.
Minimal reproduction of the problem with instructions
I have the following template & method:
<button (click)="login()">Click me</button>
inside the login method:
public login(): void {
this.webService
.post('auth/login', { username: this.username, password: this.password })
.subscribe((data: any) => {
console.log('sucess');
}, (err: any) => {
console.log('errror');
});
}
And then in the web service:
public post(url: string, body: any): Observable<any> {
return this.post2(url, body);
}
and the 2nd method:
public post2(url: string, body: any): Observable<any> {
return this.http.post('/auth/login', body);
}
If I call the method post2
directly in the login
function then everything works and I see the success message.
What is the motivation / use case for changing the behavior?
Environment
Angular version: 5.2.7
Browser: - [X] Chrome (desktop) version 66