首页 > 解决方案 > 无法在角度模板中绑定对象属性

问题描述

我无法在角度模板中绑定对象。我的变量“过滤器”有我需要的对象。它是 Current 类型,我想在表格中显示 Current 接口的属性。但是,当我尝试在模板中绑定对象时,我会得到一个下拉列表作为“module.exports”。我是角度新手,不明白它的含义。在我看到的大多数示例代码中,我应该能够直接将 Object.Property 绑定到我的 html 元素。请帮忙。

html:

            <tr>
                <td>{{filter}}</td>
                <td></td>
            </tr>
        </table>

零件:

 weatherData : Weather | undefined;
    filter!:Current;
    sub!: Subscription;
    getData(){
        this.sub = this.weatherService.getCurrentData(this.inputText).subscribe(x=>this.Observer(x));
    }
    Observer(x: Weather): void {
        this.weatherData = x;
        console.log(this.weatherData.current);
        this.filter = this.weatherData.current;
    }

当前界面在此处输入图像描述

export interface Current{
    time: string,
    temperature: number,
}

标签: htmlangulartypescript

解决方案


您将接口定义为Current但调用它CurrentClass

尝试将其更改为: filter!:Current;


推荐阅读