Closed yusuf99 closed 6 years ago
To add headers you must add some type of interceptor, the most recent versions of angular already include a way to do it or you can search for a package that will help you in that case.
Please let me know if below code will call any angular2/4 code so that we can add authorization header using interceptor or it will call directly API method.
[source]="http://localhost/api/v1/searchame?name=t"
You can use a function:
[source]="searchName.bind(this)"
And the function called:
// MyComponent
public searchName(name: string): any {
// Which using the HttpClient
// You can add headers when calling httpClient.get()
return this.myNameService.get(name);
}
// MyNameService
public get(name: string): Observable<any> {
// Build your url and you headers
return this.http.get(url, {headers: headers})
.map((response: Response) => <any>response.json());
}
thanks @rsaenen Observable is the way I think of.
I am using below URL for typeahead, Please let me know how can I pass the authorization header ?
<input class="form-control editor-focusable ng-untouched ng-pristine ng-valid" ngui-auto-complete [source]="http://localhost/api/v1/searchame?name=t" />