ng2-ui / auto-complete

Angular Auto Complete component and directive
https://ng2-ui.github.io/dist/#/auto-complete
MIT License
279 stars 123 forks source link

Authorization header #299

Closed yusuf99 closed 6 years ago

yusuf99 commented 6 years ago

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" />

politoxela commented 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.

FullStackDeveloper11 commented 6 years ago

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"

rsaenen commented 6 years ago

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());
}
allenhwkim commented 6 years ago

thanks @rsaenen Observable is the way I think of.