【发布时间】:2019-01-23 15:15:58
【问题描述】:
如何在我的简单 component.html 文件中查看有关变量的信息:cityInfo? 这是 component.html 文件,它是一个非常基本的组件,但我想用 component.ts 文件进行数据绑定。 我该怎么办?
<div>
<p>
weather works! {{cityInfo}}
</p>
</div>
这是我的 component.ts。 使用 getWeather(city),我发出一个 http 请求并返回一个 JSON 文件。
export class WeatherComponent implements OnInit {
public cityVisual: City;
constructor(
private weather: WeatherService,
) { }
ngOnInit() {
}
weatherCity(city: string) {
this.weather.getWeather(city).subscribe(resp => {
this.cityVisual = resp;
console.log(this.cityVisual.name);
});
}
}
我想在我的 component.html 文件中查看“天气工作!nameCity”输出 我怎样才能做到这一点? 请帮帮我...
【问题讨论】:
标签: angular typescript data-binding