【问题标题】:Property 'post' does not exist on type 'HttpClientModule'.ts(2339) ionic4 && angular 7'HttpClientModule'.ts(2339) ionic4 && angular 7 类型上不存在属性'post'
【发布时间】:2019-07-23 13:07:17
【问题描述】:

ionic4 中类型“HttpClient”.ts(2339) 上不存在属性“post”

onFormSubmit() {

    let data = 'CardNo=' + '25498' + '&Password=' + '123' + '&DeviceId=' + 'njfngjfg' + '&DeviceType=' + 'android';
this.onFormSubmit = this.http.post('http://dashboard.doit.aw:8081/doit_copy/user2/login', data,

    {
        headers: {
          //'content':"application/json",
          //'content-type':"application/x-www-form-urlencoded"
          'Doittoken': "TVRJek5EVWhRQ01r"
        }
    });
    return this.onFormSubmit;

 }

post 方法出错

【问题讨论】:

    标签: ionic4


    【解决方案1】:

    您正在尝试做的是在您的组件中使用 HttpClientModule 进行 http 调用。这是错误的

    您需要使用 HttpClient 而不是 HttpClientModule 来发出 http 请求。

    在 app.module.ts 中,导入 HttpClientModule(参见下面的“导入”):

    import { HttpClientModule } from '@angular/common/http';
    @NgModule({
        imports: [
              HttpClientModule,
        ...
        ],
        ...
    })
    export class AppModule { }
    

    然后,在 app.component.ts 中导入 HttpClient:

    import { HttpClient } from '@angular/common/http';
    

    现在,将您的 AppComponent 从

    constructor(private http: HttpClientModule){};
    

    constructor(private http: HttpClient){};
    

    【讨论】:

    • 如果解决了您的问题,请将答案标记为正确。
    猜你喜欢
    • 2021-01-10
    • 2021-07-02
    • 2019-08-11
    • 2021-08-02
    • 2020-06-02
    • 2022-07-09
    • 2022-10-04
    • 2023-02-07
    • 2020-08-23
    相关资源
    最近更新 更多