Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/391.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将url参数传递给angular 2中的http get请求_Javascript_Http_Angular - Fatal编程技术网

Javascript 将url参数传递给angular 2中的http get请求

Javascript 将url参数传递给angular 2中的http get请求,javascript,http,angular,Javascript,Http,Angular,我试图在angular 2中将url参数传递给http get请求,但控制台中出现错误: 实例化错误{u包装器消息:“DI异常”, _originalException:TypeError:options.search.clone不是函数 在BaseRequestOptions.RequestOptions.merge 这是密码 服务 var url = '/company/' + companyUnqName + '/logs' ; app.AuditLogsHttpService

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

实例化错误{u包装器消息:“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;
          });
}
getLogs:function(){

var params=new ng.http.URLSearchParams();//我在代码中找不到
url
的值。你有吗?url是在组件var url='/company/'+companyUnqName+'/logs/'+'之前定义的;请更新它,以便有人能够理解你想要什么。很抱歉,url是在'app.AuditLogsHttpService'之前定义的