【问题标题】:Angular 6 error TS1135: Argument expression expectedAngular 6 错误 TS1135:需要参数表达式
【发布时间】:2022-03-03 20:04:38
【问题描述】:

我正在关注如何通过此链接构建 MEAN 堆栈的教程:https://www.youtube.com/watch?v=wtIvu085uU0,但是我坚持在 59:34 左右创建角度部分。本教程使用的是 angular2,而我使用的是 angular6。阻碍我的主要部分是contact.service.ts,并让addContacts、getContacts和deleteContact方法工作,因为.map方法自角度2以来发生了变化。我将他的代码更改为:

getContacts() {
    return this.http.get('http://localhost:3000/api/contacts')
        .map(res => res.json());
}

返回“属性'map'不存在类型'Observable'”错误

getContacts() {
    return this.http.get('http://localhost:3000/api/contacts')
        .pipe(
            .map(res => res.json())
        );
}

现在返回“src/app/contact.service.ts(17,7) 中的错误:错误 TS1135:需要参数表达式。”在控制台中 我想我已经克服了地图错误,但我不知道 Argument 表达式预期错误的含义。其他两种方法在将地图更改为管道之前和之后都有同样的问题。 像现在这样,它不会编译和显示视频中在 1:03:37 显示的“联系人作品”页面。控制台在其他类中没有显示其他错误,所以我认为这是唯一的错误。

【问题讨论】:

    标签: angular mean-stack


    【解决方案1】:

    重新格式化您的代码后,答案显而易见。在致电map() 之前,您有错误的.

    getContacts() {
        return this.http.get('http://localhost:3000/api/contacts')
            .pipe(
                .map(res => res.json())
             // ^ remove this period
            );
    }
    

    【讨论】:

      【解决方案2】:

      无论 Sean 说什么,加上你必须导入 map 运算符: import {map} from 'rxjs/operators'; 在文件的开头

      【讨论】:

        猜你喜欢
        • 2020-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-11-15
        • 2018-07-14
        • 1970-01-01
        • 2014-05-19
        • 2021-01-04
        相关资源
        最近更新 更多