在angular 2中向http get请求传递url参数

Passing url arguments to http get request in angular 2

本文关键字:url 参数 请求 get angular 中向 http      更新时间:2024-02-28

我试图将url参数传递到angular 2中的http get请求,但在控制台中遇到错误:

InstantiationError{_wrapperMessage:"DI异常",_originalException:TypeError:options.search.clone不是函数在BaseRequestOptions.RequestOptions.merge…

这是代码

服务

  var url = '/company/' + companyUnqName + '/logs' ;  
  app.AuditLogsHttpService = ng.core.Injectable().Class({
      constructor: [ng.http.Http,  function(http){
        this.http = http
      }],
      getLogs: function(){
        var params = new URLSearchParams();
        params.set('uniquepage', 1);
        return this.http.get(url, {search: params}) 
              .map(function (res) {
                  return res;
              });
      }
});

组件

app.AuditLogs =
  ng.core.Component({
    selector: 'audit-logs',
    providers: [ng.http.HTTP_PROVIDERS, httpService],
    templateUrl: '/public/webapp/ng2/audit_logs/audit-logs.html'
  })
  .Class({
    constructor:[ng.http.Http, httpService, function(http, service) {
      this.result = {};
      this.http = http;
      service.getLogs().subscribe(function(result){
        this.result = JSON.parse(result._body);
        this.logs = this.result.body.logs;
      }.bind(this));
    }],
});

我将使用以下内容:

getLogs: function(){
     var params = new ng.http.URLSearchParams(); // <--------
  params.set('uniquepage', 1);
  return this.http.get(url, {search: params})   
          .map(function (res) {
            return res;
          });
}

URLSearchParams对象在"ng.http.".

下定义