在angular 2中向http get请求传递url参数
Passing url arguments to http get request in angular 2
我试图将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.".
相关文章:
- 通过Javascript将HTML中的电话号码与URL参数进行交换
- 如何使用Javascript从URL参数中自动填充文本字段
- 如何将Google Analytics配置为将URL参数作为单个页面进行跟踪
- 在url参数javascript中存储键值对列表
- backbone.js-映射标准url参数-使用多个参数
- 将URL参数传递给ui sref
- Javascript从字符串中剥离所有url参数
- Javascript/jQuery获取所有url参数并添加/更改一个参数
- 在页面加载完成之前,使用URL参数运行JavaScript
- 使用Javascript获取URL参数
- 如何在 JavaScript 中解析 URL 参数
- 主干.js将 url 参数传递给集合
- 谷歌应用脚本中的 UrlFetchApp.fetch 删除 url 参数
- 通过javascript将url参数传递到多个不同的href链接中
- 角度 1 - 获取当前 URL 参数
- 使用jquery获取url参数
- 在Javascript代码中插入URL参数
- Angular 2:HTTP Post Request,带有URL参数和正文类型参数
- 限制与AngularJS状态匹配的动态URL参数的最佳方式
- 如何根据URL参数生成包含JS内容的单个HTML文件