admin管理员组

文章数量:1277383

I have a problem in Angular 2, I know this is a recurring problem, but I could not find the resolution. I made a service which is called from another Component, is no problem there.

The problem was in the service, I'm trying to make a http POST and get and 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 capture
plete error capture

Apparently the error is given in handleErrorObservable, because the post is not executed either, looking at the network tab in Chrome I do not see any POST call to the API.

Here my service Code.

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions } from '@angular/http';
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { User } from "./user";
import { HttpHeaders } from '@angular/mon/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);
    }
}

Thanks to all, any help is wele.

I have a problem in Angular 2, I know this is a recurring problem, but I could not find the resolution. I made a service which is called from another Component, is no problem there.

The problem was in the service, I'm trying to make a http POST and get and 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 capture
plete error capture

Apparently the error is given in handleErrorObservable, because the post is not executed either, looking at the network tab in Chrome I do not see any POST call to the API.

Here my service Code.

import { Injectable } from '@angular/core';
import { Http, Response, RequestOptions } from '@angular/http';
import { Observable } from "rxjs/Observable";
import 'rxjs/add/operator/catch';
import 'rxjs/add/operator/map';
import { User } from "./user";
import { HttpHeaders } from '@angular/mon/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);
    }
}

Thanks to all, any help is wele.

Share Improve this question edited Mar 14, 2023 at 4:38 Jason Aller 3,65228 gold badges41 silver badges39 bronze badges asked Feb 11, 2018 at 21:45 Franco EchevarríaFranco Echevarría 1491 gold badge4 silver badges13 bronze badges 7
  • http is being deprecated. Try using http client. before everything try to make a post call using POSTMAN or any other clients and see if you are getting the response. – Ragavan Rajan Commented Feb 11, 2018 at 21:49
  • Yes, its tested with postman and works well. Now, I need to make the request with Angular service. – Franco Echevarría Commented Feb 11, 2018 at 22:00
  • why are you stringifying the body for the POST-request? you should pass a JS-object to it – Boris Lobanov Commented Feb 11, 2018 at 22:08
  • Yes, but now I removed it, just to be sure that that was not part of the problem. – Franco Echevarría Commented Feb 11, 2018 at 22:11
  • I don't see the part where you subscribe to the Observable – Boris Lobanov Commented Feb 11, 2018 at 22:45
 |  Show 2 more ments

1 Answer 1

Reset to default 7

Based on what I've seen I can assume that the reason your request is not being sent is that you don't call .subscribe anywhere on you observable. Observables are just functions and they are not executed until you call them. That's what subscribe does - calls the functions and all the operators are then executed as well.

What you are seeing in the developers tools is not the actual error from the request, it's the message to you that you cannot view the arguments or the caller, or the callee of the function in developer's tools.

So the solution is to simply add the subscribe call (or async pipe would also do the job).

本文标签: