类型“HttpClientModule”.ts(2339)ionic4&&7上不存在属性“post”
ionic4中的类型“HttpClient”.ts2339上不存在属性“post”类型“HttpClientModule”.ts(2339)ionic4&&7上不存在属性“post”,ionic4,Ionic4,ionic4中的类型“HttpClient”.ts2339上不存在属性“post” onFormSubmit() { let data = 'CardNo=' + '25498' + '&Password=' + '123' + '&DeviceId=' + 'njfngjfg' + '&DeviceType=' + 'android'; this.onFormSubmit = this.http.post('http://dashboard.doit.aw:8
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方法获取错误您尝试在组件中使用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){};