简体   繁体   中英

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. 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

     ...
     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?

I post the answer given from ryan-m, which might help someone else who has the same question.

« 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. 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. »

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM