【发布时间】:2017-06-14 17:16:15
【问题描述】:
我正在从后端获取数据
我的服务
getItalianTeams() {
return this.http.get("https://raw.githubusercontent.com/opendatajson/football.json/master/2016-17/it.111.clubs.json")
.map(result => result.json());
}
我的订阅者
ngOnInit() {
this.teamService.getItalianTeams()
.subscribe (
(data) => {
this.teams = data.clubs;
}
)
}
}
例如,后端更改了一些数据。 如何在我的组件中收听它?
【问题讨论】:
-
后端到前端的通信通常使用 websockets 处理:developer.mozilla.org/en-US/docs/Web/API/WebSocket。除非您正在执行长轮询之类的操作,否则 http 请求只是 1 次:pubnub.com/blog/…
标签: angular typescript stream rxjs observable