Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular Header/Http/RequestOptions自Angular 6.0以来已弃用,如何将其更新为Angular 8.0?_Angular_Typescript_Http - Fatal编程技术网

Angular Header/Http/RequestOptions自Angular 6.0以来已弃用,如何将其更新为Angular 8.0?

Angular Header/Http/RequestOptions自Angular 6.0以来已弃用,如何将其更新为Angular 8.0?,angular,typescript,http,Angular,Typescript,Http,在angular 6.0中执行httprequest时,我有一个代码块 我尝试使用angular 8.0提供的更新版本,即HttpClient、HttpResponse和HttpHeader。但所有语法都不匹配。如何将8.0中较新的语法添加到此中?您应该像这样从@angular/common/http导入: import { HttpClient, HttpHeaders } from '@angular/common/http'; HTTP是HTTPClient Headers是HttpH

在angular 6.0中执行httprequest时,我有一个代码块


我尝试使用angular 8.0提供的更新版本,即HttpClient、HttpResponse和HttpHeader。但所有语法都不匹配。如何将8.0中较新的语法添加到此中?

您应该像这样从
@angular/common/http
导入:

import { HttpClient, HttpHeaders } from '@angular/common/http';
HTTP
HTTPClient
Headers
HttpHeaders

没有选择

例如:

let headers = new HttpHeaders({
    'Content-Type': 'application/json'
 });
 let options = {
    headers: headers
 }

this.http.post(URL, param, options)....
@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  declarations: [
    AppComponent,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}
参考官方文件-

确保在父模块中导入HttpClientModule[

例如:

let headers = new HttpHeaders({
    'Content-Type': 'application/json'
 });
 let options = {
    headers: headers
 }

this.http.post(URL, param, options)....
@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  declarations: [
    AppComponent,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

您应该像这样从
@angular/common/http
导入:

import { HttpClient, HttpHeaders } from '@angular/common/http';
HTTP
HTTPClient
Headers
HttpHeaders

没有选择

例如:

let headers = new HttpHeaders({
    'Content-Type': 'application/json'
 });
 let options = {
    headers: headers
 }

this.http.post(URL, param, options)....
@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  declarations: [
    AppComponent,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}
参考官方文件-

确保在父模块中导入HttpClientModule[

例如:

let headers = new HttpHeaders({
    'Content-Type': 'application/json'
 });
 let options = {
    headers: headers
 }

this.http.post(URL, param, options)....
@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  declarations: [
    AppComponent,
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {}

确保在
app.module.ts
中导入了
HttpClientModule
。 将
HttpClientModule
导入
AppModule
后,可以将
HttpClient
注入应用程序/服务类

您需要在服务中从
'@angular/common/http';
导入
HttpClient

import { HttpClient, HttpResponse, HttpHeaders } from '@angular/common/http';
在您的服务中插入
HttpClient
代替
Http
,并使用该实例发出Http请求

post(url: string, value: any) {
  const headers = new HttpHeaders().append('X-UDS-USER', sessionStorage.getItem('username'))
  .append('token', sessionStorage.getItem('token'));

  return this.http.post(url, value, {headers: headers}).map(response: HttpResponse) => {
    // do something  with response here
  }
}

确保在
app.module.ts
中导入了
HttpClientModule
。 将
HttpClientModule
导入
AppModule
后,可以将
HttpClient
注入应用程序/服务类

您需要在服务中从
'@angular/common/http';
导入
HttpClient

import { HttpClient, HttpResponse, HttpHeaders } from '@angular/common/http';
在您的服务中插入
HttpClient
代替
Http
,并使用该实例发出Http请求

post(url: string, value: any) {
  const headers = new HttpHeaders().append('X-UDS-USER', sessionStorage.getItem('username'))
  .append('token', sessionStorage.getItem('token'));

  return this.http.post(url, value, {headers: headers}).map(response: HttpResponse) => {
    // do something  with response here
  }
}

您好,我对我的代码进行了以下更新,但未找到响应您好,我对我的代码进行了以下更新,但未找到响应谢谢,是否按照建议进行了更改,但未找到响应谢谢,是否按照建议进行了更改,但未找到响应