1

I am trying to pass url args to http get request in angular 2 but getting an error in the console:

InstantiationError {_wrapperMessage: "DI Exception", _originalException: TypeError: options.search.clone is not a function at BaseRequestOptions.RequestOptions.merge....

here's the code

Service

  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;
              });
      }
});

Component

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));
    }],
});
4
  • I cant find url's value in code. do you have it? Commented Apr 8, 2016 at 6:59
  • url is defined before the component var url = '/company/' + companyUnqName + '/logs/' + ; Commented Apr 8, 2016 at 7:02
  • please update it so some one can understand what do you want. Commented Apr 8, 2016 at 7:03
  • sorry for that, url is defined before the 'app.AuditLogsHttpService' Commented Apr 8, 2016 at 7:13

1 Answer 1

2

I would use the following:

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

The URLSearchParams object is defined under "ng.http.".

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.