Type 'Headers' has no properties in common with type 'RequestOptionsArgs'?

后端 未结 1 1498
盖世英雄少女心
盖世英雄少女心 2020-12-14 08:24

I just made two important upgrades to our Angular 4 application and build tools:

  1. @angular/core ^4.1.3 => ^4.2.4 (and /http,
相关标签:
1条回答
  • 2020-12-14 09:12

    Update for 4.3 HttpClient

    The new syntax to be compatible with HttpClient, introduced in angular 4.3, is:

    import { HttpClient, HttpHeaders } from "@angular/common/http";
    
    private _options = { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) };
    

    No more RequestOptions: parameters are added using the new immutable HttpParams Map.

    Pre 4.3 / Http

    I just noticed that RequestOptions now requires you to explicitly pass named options as an object, like:

    headers: Headers = new Headers({ 'Content-Type': 'application/json' });
    options: RequestOptions = new RequestOptions({ headers: this.headers });
    
    0 讨论(0)
提交回复
热议问题