[英]Most efficient way to get the same data in parent and child component in AngularJS?
I actually make two calls from the same API to get the same data.实际上,我从同一个 API 进行了两次调用以获取相同的数据。 One from the parent component and one from the child component.
一个来自父组件,一个来自子组件。
This is the way I get my data in parent.js
and child.js
这是我在
parent.js
和child.js
中获取数据的方式
...
this.cyclistService.cyclistInfo().subscribe(
(cyclist) => {
this.cyclist = cyclist
}
)
...
In order to reduce network latency, should I make the API call in both places or just pass the data locally?为了减少网络延迟,我应该在两个地方都进行 API 调用还是只在本地传递数据?
I post the answer given from ryan-m, which might help someone else who has the same question.我发布了ryan-m 给出的答案,这可能会帮助其他有同样问题的人。
« Just pass the data locally. «只需在本地传递数据。 Redundant API calls are always going to be slower because network latency on a phone is potentially a lot, and you could have one fail but not the other, and all sorts of fun things to think about.
冗余的 API 调用总是会变慢,因为手机上的网络延迟可能会很大,你可能会失败一个但不会失败,还有各种有趣的事情需要考虑。 Reducing the number of API calls you need to make from a mobile device is always good if you have a way to do it without sacrificing correctness.
减少需要从移动设备拨打的 API 电话的数量总是好的,如果您有办法在不牺牲正确性的情况下做到这一点。 »
»
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.