Reputation: 49
I'm trying to pass the userId to the headers in this call:
api.service.ts
onUpdateJamItMessageBoard( dispMsg: any, dispStartTs: any, dispEndTs: any, userId: any) {
const url = this.updateJamItMessageBoard + 'messages';
const params = new HttpParams()
.set('dispMsg', String(dispMsg))
.set('dispStartTs', String(dispStartTs))
.set('dispEndTs', String(dispEndTs));
const headers = new HttpHeaders({
'userId': String (userId)
});
return this.http.post<JamIt>(url, null, {
params: params, headers: headers
});
}
I'm subscribing to it here:
jamit.component.ts
onUpdateJamIt() {
let dispMsg = this.jamItMessageForMessageCenter + ' ' + this.jamItMessage + ' ' + this.freeText;
let dispStartTs = this.startTimer;
let dispEndTs = this.endTimer;
let userId = '';
this.apiEndPointService.onUpdateJamItMessageBoard(dispMsg.trim(), dispStartTs.trim(), dispEndTs.trim(), userId.trim()).subscribe(response => {
console.log(response)
});
}
and here's where I use it in the HTML:
jamit.component.html
<button mat-raised-button color="warn" (click)="onUpdateJamIt()">Update</button>
When I click on the click event, I pass all the other parameters except the UserId and I don't know why. Please help. Am I doing it wrong? Or is there something I'm missing?
Upvotes: 0
Views: 2004
Reputation: 86790
Try this -
const headers = new HttpHeaders();
headers.set('userId', userId);
For more information check out here -
Upvotes: 1