Angular 2 - http get withCredentials

后端 未结 1 1818
孤街浪徒
孤街浪徒 2021-01-24 11:23

I found something regarding this, but most examples and explanations are deprecated and it\'s not applicable to RC1.

import {Injectable} from \"@angular/core\";         


        
相关标签:
1条回答
  • 2021-01-24 11:59

    With RC1 you need to extend the BrowserXhr class:

    @Injectable()
    export class CustomBrowserXhr extends BrowserXhr {
      constructor() {}
      build(): any {
        let xhr = super.build();
        xhr.withCredentials = true;
        return <any>(xhr);
      }
    }
    

    and override the BrowserXhr provider with the extended:

    bootstrap(AppComponent, [
      HTTP_PROVIDERS,
      provide(BrowserXhr, { useClass: CustomBrowserXhr })
    ]);
    

    With the upcoming RC2, you'll be able to use a withCredentials attribute in request options.

    See these links for more details:

    • http://5thingsangular.github.io/2016/05/30/issue-6.html
    • https://github.com/angular/angular/pull/7281
    0 讨论(0)
提交回复
热议问题