POST auth-service.ts ionic 3 app 上的语法错误



>im 使用 ionic 3.20.0 ,我在这一行有错误

postData(credentials, type) {
return new Promise((resolve, reject) =>{
let headers = new Headers();
console.log(headers);
this.http.post(apiUrl+type, JSON.stringify(credentials), {headers:headers}).
subscribe(res =>{
resolve(res.json());
}, (err) =>{
reject(err);
});
});

在 auth-service.ts 中,t 在{headers:headers}处显示语法错误

为什么会这样...所述的错误

类型为"{ headers: Headers; }"的参数不能分配给类型为"{ headers?"的参数:HttpHeaders |{ [标头: 字符串]: 字符串 | 字符串[]; };观察?:"身体";参数?:唔...'。
属性"标头"的类型不兼容。类型">
标头"不能分配给类型"HttpHeaders |{ [header: string]: string | string[]; }'.类型"标头
"不能分配给类型"{ [标头:字符串]:字符串 | 字符串[]; }"。
类型"标头"中缺少索引签名。

任何人都可以指导我,我在教程视频中看到,那个没有错误的家伙

我认为您没有在app.module.ts文件中
添加"HttpModule"。

您需要在 app.module.ts 中添加"HttpModule",如下所示:

1] 导入 HttpModule,如下所示:

import { HttpModule } from '@angular/http'; 

2] 在导入中添加 HttpModule 条目:

@NgModule({
declarations: [
...
],
imports: [
...
HttpModule,
...
]
})

最新更新