http post 错误:未捕获的类型错误:"调用方"和"参数"是受限制的函数属性,无法在此上下文中访问



我正在尝试使用:

在Angular 2中执行帖子
let headers = new Headers({'Content-Type': 'application/json'}) ;
let options = new RequestOptions({ headers: headers });
this._http.post(this._healthFromControllerJsonPostUrl + "/MyAction", JSON.stringify("asdf"), options);

我正在使用ES6

"module": "es6"

我得到此错误

this._http.__proto__.post.arguments:
    Uncaught TypeError: 'caller' and 'arguments' are restricted function properties and cannot be accessed in this context.
        at eval (eval at evaluate (:85:21), <anonymous>:1:26)

我已经验证了我的URL是正确的。我发现一些文章是因为ES6和严格的模式。

  • 在这种情况下,我应该禁用严格模式吗?
  • 我该如何解决这个错误?

尝试类似的东西:

import {Headers, Http} from '@angular/http';
import 'rxjs/add/operator/toPromise';
@Injectable()
export class myServiceClass {
private headers = new Headers({'Content-Type': 'application/json'});
constructor(private http: Http) {};
this.http
      .post(this._healthFromControllerJsonPostUrl, JSON.stringify('asdf'), {headers: this.headers})
      .toPromise()
      .then(response => response.json().data)
      .catch(this.handleError);
private handleError(error: any): Promise<any> {
    return Promise.reject(error.message || error);
  }
}

因为我没有看到您的完整组件,所以我真的不知道您的问题是否与您的呼叫,与您的实例或使用依赖关系有关的方式有关...所以我决定发布一个简单的示例,希望这对您有所帮助,如果没有,请不要犹豫,以提出更多信息,以便我们找出您的问题的来源。

希望它能有所帮助!;)

相关内容

最新更新