About angular api call and component communication











up vote
0
down vote

favorite












I have a component product.component.ts in which i have all data of multiple product which i got by api call



@Component({
selector: 'app-pinfo',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})


then after displaying all porduct on this component when i click the single product ,I navigate to detailedproductinfo component and i pass product id as navigation parameter i am intrested in know that what i do for detailed data about product from following




  1. Api call to getproductinfobyid(id) or


  2. pass data from product component because i have already product related data in product component



I am intrested in know that which method will enhance performance from above and what take time more in angular from below




  1. passing data between component by using service or


  2. api call by using http











share|improve this question
























  • for sure, use shared service or @input annotation for data you want to pass to child component
    – Vinko Vorih
    Nov 20 at 9:46










  • If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
    – sloth
    Nov 20 at 9:48










  • i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
    – N K
    Nov 20 at 9:48












  • As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
    – kedenk
    Nov 20 at 9:51

















up vote
0
down vote

favorite












I have a component product.component.ts in which i have all data of multiple product which i got by api call



@Component({
selector: 'app-pinfo',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})


then after displaying all porduct on this component when i click the single product ,I navigate to detailedproductinfo component and i pass product id as navigation parameter i am intrested in know that what i do for detailed data about product from following




  1. Api call to getproductinfobyid(id) or


  2. pass data from product component because i have already product related data in product component



I am intrested in know that which method will enhance performance from above and what take time more in angular from below




  1. passing data between component by using service or


  2. api call by using http











share|improve this question
























  • for sure, use shared service or @input annotation for data you want to pass to child component
    – Vinko Vorih
    Nov 20 at 9:46










  • If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
    – sloth
    Nov 20 at 9:48










  • i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
    – N K
    Nov 20 at 9:48












  • As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
    – kedenk
    Nov 20 at 9:51















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have a component product.component.ts in which i have all data of multiple product which i got by api call



@Component({
selector: 'app-pinfo',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})


then after displaying all porduct on this component when i click the single product ,I navigate to detailedproductinfo component and i pass product id as navigation parameter i am intrested in know that what i do for detailed data about product from following




  1. Api call to getproductinfobyid(id) or


  2. pass data from product component because i have already product related data in product component



I am intrested in know that which method will enhance performance from above and what take time more in angular from below




  1. passing data between component by using service or


  2. api call by using http











share|improve this question















I have a component product.component.ts in which i have all data of multiple product which i got by api call



@Component({
selector: 'app-pinfo',
templateUrl: './product.component.html',
styleUrls: ['./product.component.css']
})


then after displaying all porduct on this component when i click the single product ,I navigate to detailedproductinfo component and i pass product id as navigation parameter i am intrested in know that what i do for detailed data about product from following




  1. Api call to getproductinfobyid(id) or


  2. pass data from product component because i have already product related data in product component



I am intrested in know that which method will enhance performance from above and what take time more in angular from below




  1. passing data between component by using service or


  2. api call by using http








angular angular-components angular-router angular-httpclient






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 9:46









sloth

72.6k14127168




72.6k14127168










asked Nov 20 at 9:43









N K

325




325












  • for sure, use shared service or @input annotation for data you want to pass to child component
    – Vinko Vorih
    Nov 20 at 9:46










  • If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
    – sloth
    Nov 20 at 9:48










  • i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
    – N K
    Nov 20 at 9:48












  • As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
    – kedenk
    Nov 20 at 9:51




















  • for sure, use shared service or @input annotation for data you want to pass to child component
    – Vinko Vorih
    Nov 20 at 9:46










  • If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
    – sloth
    Nov 20 at 9:48










  • i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
    – N K
    Nov 20 at 9:48












  • As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
    – kedenk
    Nov 20 at 9:51


















for sure, use shared service or @input annotation for data you want to pass to child component
– Vinko Vorih
Nov 20 at 9:46




for sure, use shared service or @input annotation for data you want to pass to child component
– Vinko Vorih
Nov 20 at 9:46












If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
– sloth
Nov 20 at 9:48




If you already have all the data you need in memory it's obviously faster to just pass it to another component than reloading it again from an external source.
– sloth
Nov 20 at 9:48












i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
– N K
Nov 20 at 9:48






i am not using detailedproductinfo as child component it is completely independent component @VinkoVorih
– N K
Nov 20 at 9:48














As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
– kedenk
Nov 20 at 9:51






As earlier mentioned, if you have the data already, just pass it to the component. However, you can speed up everything further if you download only a list of product names and ids in your product component. At the time you want to display a specific product use you getproductinfobyid. However, this depends on the size of the product entity and the number of products. You do not have to download all products with all information if not necessary.
– kedenk
Nov 20 at 9:51














1 Answer
1






active

oldest

votes

















up vote
1
down vote













Although there are multiple ways of dealing with this, it completely depends on these things:




  1. Whether the Products API return the complete details for each product. Or whether they just return the relevant details based on what you'd like to show on the Product List Page.

  2. Whether the Products API is in your control and you decide what data it is supposed to return.

  3. The number of fields that the data model for each product has.


Keeping all this in mind, if the number of fields is quite a lot for each product, then I don't think it's appropriate to return the details of all the products via the products API. The specific details for each product should be returned by products/:id API which would take ProductId as a param.



So in this case, getting the Id from the ActivatedRoute and then calling /products/:id API to get the Product Details would make more sense.



If on the other hand, the data model for a product is not that big, it's totally fine to return the complete details of the products via the products API.



So in this case, passing the selected product data via a SharedService would be the approach to go for.






share|improve this answer





















    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390143%2fabout-angular-api-call-and-component-communication%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote













    Although there are multiple ways of dealing with this, it completely depends on these things:




    1. Whether the Products API return the complete details for each product. Or whether they just return the relevant details based on what you'd like to show on the Product List Page.

    2. Whether the Products API is in your control and you decide what data it is supposed to return.

    3. The number of fields that the data model for each product has.


    Keeping all this in mind, if the number of fields is quite a lot for each product, then I don't think it's appropriate to return the details of all the products via the products API. The specific details for each product should be returned by products/:id API which would take ProductId as a param.



    So in this case, getting the Id from the ActivatedRoute and then calling /products/:id API to get the Product Details would make more sense.



    If on the other hand, the data model for a product is not that big, it's totally fine to return the complete details of the products via the products API.



    So in this case, passing the selected product data via a SharedService would be the approach to go for.






    share|improve this answer

























      up vote
      1
      down vote













      Although there are multiple ways of dealing with this, it completely depends on these things:




      1. Whether the Products API return the complete details for each product. Or whether they just return the relevant details based on what you'd like to show on the Product List Page.

      2. Whether the Products API is in your control and you decide what data it is supposed to return.

      3. The number of fields that the data model for each product has.


      Keeping all this in mind, if the number of fields is quite a lot for each product, then I don't think it's appropriate to return the details of all the products via the products API. The specific details for each product should be returned by products/:id API which would take ProductId as a param.



      So in this case, getting the Id from the ActivatedRoute and then calling /products/:id API to get the Product Details would make more sense.



      If on the other hand, the data model for a product is not that big, it's totally fine to return the complete details of the products via the products API.



      So in this case, passing the selected product data via a SharedService would be the approach to go for.






      share|improve this answer























        up vote
        1
        down vote










        up vote
        1
        down vote









        Although there are multiple ways of dealing with this, it completely depends on these things:




        1. Whether the Products API return the complete details for each product. Or whether they just return the relevant details based on what you'd like to show on the Product List Page.

        2. Whether the Products API is in your control and you decide what data it is supposed to return.

        3. The number of fields that the data model for each product has.


        Keeping all this in mind, if the number of fields is quite a lot for each product, then I don't think it's appropriate to return the details of all the products via the products API. The specific details for each product should be returned by products/:id API which would take ProductId as a param.



        So in this case, getting the Id from the ActivatedRoute and then calling /products/:id API to get the Product Details would make more sense.



        If on the other hand, the data model for a product is not that big, it's totally fine to return the complete details of the products via the products API.



        So in this case, passing the selected product data via a SharedService would be the approach to go for.






        share|improve this answer












        Although there are multiple ways of dealing with this, it completely depends on these things:




        1. Whether the Products API return the complete details for each product. Or whether they just return the relevant details based on what you'd like to show on the Product List Page.

        2. Whether the Products API is in your control and you decide what data it is supposed to return.

        3. The number of fields that the data model for each product has.


        Keeping all this in mind, if the number of fields is quite a lot for each product, then I don't think it's appropriate to return the details of all the products via the products API. The specific details for each product should be returned by products/:id API which would take ProductId as a param.



        So in this case, getting the Id from the ActivatedRoute and then calling /products/:id API to get the Product Details would make more sense.



        If on the other hand, the data model for a product is not that big, it's totally fine to return the complete details of the products via the products API.



        So in this case, passing the selected product data via a SharedService would be the approach to go for.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 20 at 9:53









        SiddAjmera

        12.1k21137




        12.1k21137






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53390143%2fabout-angular-api-call-and-component-communication%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Wiesbaden

            Marschland

            Dieringhausen