Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

problem with adding httpheaders #424

Open
BehnamAbdy opened this issue Mar 10, 2019 · 1 comment
Open

problem with adding httpheaders #424

BehnamAbdy opened this issue Mar 10, 2019 · 1 comment

Comments

@BehnamAbdy
Copy link

BehnamAbdy commented Mar 10, 2019

hi
i want the ngautocomplete to sent a custom httpheader while calling the api but it doesnt send the added header, here is the code i use:

public dataService: RemoteData;

constructor(private completerService: CompleterService) {
this.dataService = completerService.remote(some url, 'label', 'label');
let options = new RequestOptions({ headers: new Headers() });
options.headers.set('api-key', 'some credentials');
this.dataService.requestOptions(options);
}

<ng2-completer [(ngModel)]="partTerm"
[ngModelOptions]="{standalone: true}"
[datasource]="dataService"
[clearUnselected]="true"
[inputClass]="'form-control'"
[placeholder]="'search by term'"
[minSearchLength]="2"
[pause]="500"
(selected)="selected($event)">
i'll appreciate it

@danielheth
Copy link

Looks like they changed the way request headers are passed in.

This worked for me using 1.6.3:

this.dataService = this.completerService.remote(null, 'name', 'name');
let options = new RequestOptions({
  headers: new Headers({
    Authorization: 'token ' + localStorage.getItem('token')
  })
});
(<RemoteData>this.dataService ).requestOptions(options);

This is what it looks line now that i'm using 2.0.8:

this.dataService = this.completerService.remote(null, 'name', 'name');
(<RemoteData>this.dataService).requestOptions({
  headers: {
    Authorization: 'token ' + localStorage.getItem('token')
  }
});

Believe the change occurred with release of v2.0.0
https://github.com/oferh/ng2-completer/blob/master/CHANGELOG.md

Another interesting note... the demo... https://oferh.github.io/ng2-completer/#/native (Remote data with URL Formater and Headers) doesn't add remote headers as far as i can see.. https://github.com/oferh/ng2-completer/blob/master/demo/native-cmp.ts#L94-L101

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants