2017-12-08 5 views
0

.Angularcli 헤더

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

처음에는 클래스의 헤더 값을 검색합니다.

public int ValueID { get; set; } 
    ValueID = Convert.ToInt32(HttpContext.Current.Request.Headers.GetValues("ValueID")); 

`import { Http, Response, JsonpModule, HttpModule, Headers, RequestOptions } from '@angular/http';` 
+0

이'angular' 또는'각도-js'가 있습니까? – Aravind

+0

angular2 그래서 각도가 – Sevensnake77787

답변

0

먼저 비추천 클라이언트 인 http를 사용하고 있습니다. '@angular/common/http'

post method의 두 번째 인수는 body입니다. 옵션의 경우는 3 인수 사용해야합니다 :

이 이
this._http.post(this._getreport, null, {headers: myHeaders, params: myParams}) 

RequestOptions을 사용하지 마십시오을 -이 이전 HTTP 클라이언트의 일부 deprecated

+0

좋습니다. 한번 시도해보십시오. – Sevensnake77787

+0

확인. 나는 변화를 만들었다. @Martin Nuc.'constructor (private _http2 : HttpClient) {}''ReportId (paramid : any) : 관찰 가능 { let header = new HttpHeaders; header.append ('Content-Type', 'application/json'); header.append ('ValueID', paramid); myParams를 new let HttpParams(); myParams.set ('ValueID', '587'); this._http2.post (this._getreport, null, {헤더 : 헤더, 매개 변수 : myParams})를 반환합니다. – Sevensnake77787