mta*_*gmt 2 mean-stack angular
我正在跟踪有关如何通过此链接构建MEAN堆栈的教程:https : //www.youtube.com/watch?v= wtIvu085uU0,但是我仍然坚持在59:34左右创建角度部分。本教程使用angular2,而我使用angular6。阻止我前进的主要部分是contact.service.ts,并使addContacts,getContacts和deleteContact方法能够正常工作,因为.map方法自从angular 2开始就发生了变化。
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.map(res => res.json());
}
Run Code Online (Sandbox Code Playgroud)
返回“属性'地图'在'可观察'类型上不存在”的错误
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.pipe(
.map(res => res.json())
);
}
Run Code Online (Sandbox Code Playgroud)
现在返回“ src / app / contact.service.ts(17,7)中的错误:错误TS1135:期望参数表达式。” 在控制台中,我认为我已经克服了地图错误,但是我不知道Argument表达式预期的错误是什么意思。在将地图更改为管道之前和之后,其他两种方法都存在相同的问题。现在,它不会编译并显示视频中显示的“联系人工作”页面,该页面位于1:03:37。控制台在其他类中没有显示其他错误,因此我认为这是唯一的错误。
重新格式化代码后,答案显而易见。.致电给您之前,您有误会map():
getContacts() {
return this.http.get('http://localhost:3000/api/contacts')
.pipe(
.map(res => res.json())
// ^ remove this period
);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3688 次 |
| 最近记录: |