类型'HttpClientModule'上不存在属性'post'.ts(2339)ionic4 && angular 7

时间:2019-07-23 13:07:17

标签: ionic4

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;

 }

发布方法出错

1 个答案:

答案 0 :(得分:0)

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

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

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

java.lang.UnsatisfiedLinkError: jssc.SerialNativeInterface.getSerialPortNames()[Ljava/lang/String;
at jssc.SerialNativeInterface.getSerialPortNames(Native Method)
at jssc.SerialPortList.getWindowsPortNames(SerialPortList.java:309)
at jssc.SerialPortList.getPortNames(SerialPortList.java:298)
at jssc.SerialPortList.getPortNames(SerialPortList.java:182)
at processing.serial.Serial.list(Unknown Source)
at Performance.Processing.setup(Processing.java:44)
at processing.core.PApplet.handleDraw(PApplet.java:2425)
at processing.awt.PSurfaceAWT$12.callDraw(PSurfaceAWT.java:1547)
at processing.core.PSurfaceNone$AnimationThread.run(PSurfaceNone.java:313)

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

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

现在,从以下位置更改您的AppComponent

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

constructor(private http: HttpClientModule){};