[英]Angularcli headers
What is the equivalent to jquery 相当于jquery
$scope.SetHeaders = function () {
$.ajaxSetup({
headers: {
'ValueID': ValueID
}
});
};
What I tried so far in angular cli. 到目前为止,我在angular cli中所做的尝试。
pushvalueId(paramid: number): Observable<any[]> {
let myHeaders = new Headers();
myHeaders.set('ValueID', '77');
let myParams = new URLSearchParams();
myParams.set('ValueID', paramid.toString());
let options = new RequestOptions({ headers: myHeaders, params: myParams });
return this._http.post(this._getreport, options)
}
What I am trying to do initially is retrieve the header value in my class. 我最初要做的是在类中检索标头值。
public int ValueID { get; set; }
ValueID = Convert.ToInt32(HttpContext.Current.Request.Headers.GetValues("ValueID"));
`import { Http, Response, JsonpModule, HttpModule, Headers, RequestOptions } from '@angular/http';`
First you are using deprecated http client. 首先,您正在使用不推荐使用的http客户端。 You should use
'@angular/common/http'
您应该使用
'@angular/common/http'
Second argument for post method is body
. post方法的第二个参数是
body
。 For options you have to use 3rd argument: 对于选项,您必须使用第3个参数:
this._http.post(this._getreport, null, {headers: myHeaders, params: myParams})
Don't use RequestOptions
- these are part of the old http client and deprecated 不要使用
RequestOptions
这些是旧版HTTP客户端的一部分, 已弃用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.