Javascript 将url参数传递给angular 2中的http get请求
我试图在angular 2中将url参数传递给http get请求,但控制台中出现错误: 实例化错误{u包装器消息:“DI异常”, _originalException:TypeError:options.search.clone不是函数 在BaseRequestOptions.RequestOptions.merge 这是密码 服务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
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'之前定义的