html - 无法在角度模板中绑定对象属性
问题描述
我无法在角度模板中绑定对象。我的变量“过滤器”有我需要的对象。它是 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,
}
解决方案
您将接口定义为Current
但调用它CurrentClass
。
尝试将其更改为:
filter!:Current;
推荐阅读
- typescript - 为什么即使我能够获得对我试图滚动到的元素的引用,scrollIntoView 在 Vue 3 中也不起作用
- python - 将两个列表或数组中的数据组织到字典中
- reactjs - 在 Firebase 中进行安全身份验证
- python - 在 android 上使用 ctypes 加载共享库
- amazon-web-services - Terraform如何在“ip”类型的目标组中注册已知的私有IP地址
- r - 如何在 R 中为大型数据框使用字典?
- python - 如何使用 map() 和 filter() 函数而不是 for 循环使用 Python 3 删除空目录?
- html - 如何允许使用箭头键在组中导航收音机,并使它们不可见并占用零空间?
- python-3.x - 在 URL 中使用 ID 或 Slug 以外的类字段
- java - RestAssured:如何避免在请求中发送 User-Agent 标头