HowTo: Customize HTTP headers in AJAX request

Edit on GitHub

The XMLHttpRequest method setRequestHeader() sets the value of an HTTP request header. When using setRequestHeader(), call it after calling open(), but before send(). If this method is called several times with the same header, the values are merged into a single request header.

Customize HTTP headers to ajax-provider.ts

To add custom headers to ajax-provider.ts, add this.headers.forEach((value: string, key: string) => this.xhr.setRequestHeader(key, value)); into the promise of the fetch method.

Usage example
this.ajaxProvider.headers.set('Accept', 'application/json'