错误TS2339:类型“ any []”上不存在属性“ data”

时间:2018-11-27 06:27:32

标签: angular6

我在内存数据中有一个数组,如下所示:

const menu = [
            { id: 1, title: 'Home', link: '/home' },
            { id: 2, title: 'About', link: '/about' },
            { id: 3, title: 'Services', link: '/services' }
        ];
return {menu}

从服务中调用api时,我得到如下数据:

data: Array(8)
0: {id: 1, title: "Home", link: "/home"}
1: {id: 2, title: "About", link: "/about"}
2: {id: 3, title: "Services", link: "/services"}

代码:

getSettings(database: string, id?: any): Observable<any[]> {
    let uid = id || null;
    let url: string;
    if (uid !== null) {
        url = `api/${database}/${id}`;
    } else {
        url = `api/${database}`;
    }
    return this.http.get<any>(url);
}

现在当我调用此服务时来自组件:

getMenu() {
        this.config.getSettings(this.database).subscribe(

            setting => {
                this.menu = setting.data;
                console.log(setting);
            }

        );
    }

我遇到错误:错误TS2339:类型“ any []”上不存在属性“数据”。

0 个答案:

没有答案