How to get a component/element provider injector within its node definition










0














tl;dr: During debug/development how can I can view a particular html element's provider injector or better yet its node definition.



So according to this blog post




Each view node is created using a node definition that holds metadata describing the node.



In Angular, a node definition that describes an HTML element defines its own injector. In other words, an HTML element in a component’s template defines its own element injector. And this injector can populated with providers by applying one or more directives on the corresponding HTML element.



The definition that Angular creates for this template includes the following metadata for the div element [See gist]




How can i see my element's node definition in my app during debugging? ie in my Chrome dev tools.










share|improve this question


























    0














    tl;dr: During debug/development how can I can view a particular html element's provider injector or better yet its node definition.



    So according to this blog post




    Each view node is created using a node definition that holds metadata describing the node.



    In Angular, a node definition that describes an HTML element defines its own injector. In other words, an HTML element in a component’s template defines its own element injector. And this injector can populated with providers by applying one or more directives on the corresponding HTML element.



    The definition that Angular creates for this template includes the following metadata for the div element [See gist]




    How can i see my element's node definition in my app during debugging? ie in my Chrome dev tools.










    share|improve this question
























      0












      0








      0







      tl;dr: During debug/development how can I can view a particular html element's provider injector or better yet its node definition.



      So according to this blog post




      Each view node is created using a node definition that holds metadata describing the node.



      In Angular, a node definition that describes an HTML element defines its own injector. In other words, an HTML element in a component’s template defines its own element injector. And this injector can populated with providers by applying one or more directives on the corresponding HTML element.



      The definition that Angular creates for this template includes the following metadata for the div element [See gist]




      How can i see my element's node definition in my app during debugging? ie in my Chrome dev tools.










      share|improve this question













      tl;dr: During debug/development how can I can view a particular html element's provider injector or better yet its node definition.



      So according to this blog post




      Each view node is created using a node definition that holds metadata describing the node.



      In Angular, a node definition that describes an HTML element defines its own injector. In other words, an HTML element in a component’s template defines its own element injector. And this injector can populated with providers by applying one or more directives on the corresponding HTML element.



      The definition that Angular creates for this template includes the following metadata for the div element [See gist]




      How can i see my element's node definition in my app during debugging? ie in my Chrome dev tools.







      angular dependency-injection






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 12 at 12:47









      jonyeezs

      112




      112






















          2 Answers
          2






          active

          oldest

          votes


















          0














          In Chrome dev-tools, during ng serve :



          • inspect an element of the component you want to watch

          • it will be highlighted in the dev tools Elements tab

          • find the parent tag (usually app-something)

          • click on it

          Now, if you input console.log($0) in your console, it should display this element. Don't select another element, as you would loose the context of this component.



          • input const comp = ng.probe($0).componentInstance

          You now have a reference to your component.



          I'm not sure you can have access to its injector unless you declare it as a dependency though.






          share|improve this answer




























            0














            Suppose you have the following directive that adds a provider:



            @Directive(
            selector: '[provider]',
            providers: [

            provide: 'token',
            useValue: 'value'

            ]
            )
            export class ProviderDirective
            constructor()
            console.log('Ptovider Dir');




            And use it in a template like this:



            @Component(
            selector: 'a-comp',
            template: `
            <div provider>I am div with a provider</div>
            `
            )
            export class AComponent


            To find the element definition and providers added by the directive, open a console, select the div element and type the following:



            ng.probe($0).injector.elDef


            There you'll see element property pointing to an object with public providers.






            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',
              autoActivateHeartbeat: false,
              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%2f53262515%2fhow-to-get-a-component-element-provider-injector-within-its-node-definition%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              0














              In Chrome dev-tools, during ng serve :



              • inspect an element of the component you want to watch

              • it will be highlighted in the dev tools Elements tab

              • find the parent tag (usually app-something)

              • click on it

              Now, if you input console.log($0) in your console, it should display this element. Don't select another element, as you would loose the context of this component.



              • input const comp = ng.probe($0).componentInstance

              You now have a reference to your component.



              I'm not sure you can have access to its injector unless you declare it as a dependency though.






              share|improve this answer

























                0














                In Chrome dev-tools, during ng serve :



                • inspect an element of the component you want to watch

                • it will be highlighted in the dev tools Elements tab

                • find the parent tag (usually app-something)

                • click on it

                Now, if you input console.log($0) in your console, it should display this element. Don't select another element, as you would loose the context of this component.



                • input const comp = ng.probe($0).componentInstance

                You now have a reference to your component.



                I'm not sure you can have access to its injector unless you declare it as a dependency though.






                share|improve this answer























                  0












                  0








                  0






                  In Chrome dev-tools, during ng serve :



                  • inspect an element of the component you want to watch

                  • it will be highlighted in the dev tools Elements tab

                  • find the parent tag (usually app-something)

                  • click on it

                  Now, if you input console.log($0) in your console, it should display this element. Don't select another element, as you would loose the context of this component.



                  • input const comp = ng.probe($0).componentInstance

                  You now have a reference to your component.



                  I'm not sure you can have access to its injector unless you declare it as a dependency though.






                  share|improve this answer












                  In Chrome dev-tools, during ng serve :



                  • inspect an element of the component you want to watch

                  • it will be highlighted in the dev tools Elements tab

                  • find the parent tag (usually app-something)

                  • click on it

                  Now, if you input console.log($0) in your console, it should display this element. Don't select another element, as you would loose the context of this component.



                  • input const comp = ng.probe($0).componentInstance

                  You now have a reference to your component.



                  I'm not sure you can have access to its injector unless you declare it as a dependency though.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 12 at 12:53









                  trichetriche

                  25.4k42051




                  25.4k42051























                      0














                      Suppose you have the following directive that adds a provider:



                      @Directive(
                      selector: '[provider]',
                      providers: [

                      provide: 'token',
                      useValue: 'value'

                      ]
                      )
                      export class ProviderDirective
                      constructor()
                      console.log('Ptovider Dir');




                      And use it in a template like this:



                      @Component(
                      selector: 'a-comp',
                      template: `
                      <div provider>I am div with a provider</div>
                      `
                      )
                      export class AComponent


                      To find the element definition and providers added by the directive, open a console, select the div element and type the following:



                      ng.probe($0).injector.elDef


                      There you'll see element property pointing to an object with public providers.






                      share|improve this answer



























                        0














                        Suppose you have the following directive that adds a provider:



                        @Directive(
                        selector: '[provider]',
                        providers: [

                        provide: 'token',
                        useValue: 'value'

                        ]
                        )
                        export class ProviderDirective
                        constructor()
                        console.log('Ptovider Dir');




                        And use it in a template like this:



                        @Component(
                        selector: 'a-comp',
                        template: `
                        <div provider>I am div with a provider</div>
                        `
                        )
                        export class AComponent


                        To find the element definition and providers added by the directive, open a console, select the div element and type the following:



                        ng.probe($0).injector.elDef


                        There you'll see element property pointing to an object with public providers.






                        share|improve this answer

























                          0












                          0








                          0






                          Suppose you have the following directive that adds a provider:



                          @Directive(
                          selector: '[provider]',
                          providers: [

                          provide: 'token',
                          useValue: 'value'

                          ]
                          )
                          export class ProviderDirective
                          constructor()
                          console.log('Ptovider Dir');




                          And use it in a template like this:



                          @Component(
                          selector: 'a-comp',
                          template: `
                          <div provider>I am div with a provider</div>
                          `
                          )
                          export class AComponent


                          To find the element definition and providers added by the directive, open a console, select the div element and type the following:



                          ng.probe($0).injector.elDef


                          There you'll see element property pointing to an object with public providers.






                          share|improve this answer














                          Suppose you have the following directive that adds a provider:



                          @Directive(
                          selector: '[provider]',
                          providers: [

                          provide: 'token',
                          useValue: 'value'

                          ]
                          )
                          export class ProviderDirective
                          constructor()
                          console.log('Ptovider Dir');




                          And use it in a template like this:



                          @Component(
                          selector: 'a-comp',
                          template: `
                          <div provider>I am div with a provider</div>
                          `
                          )
                          export class AComponent


                          To find the element definition and providers added by the directive, open a console, select the div element and type the following:



                          ng.probe($0).injector.elDef


                          There you'll see element property pointing to an object with public providers.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 12 at 15:17

























                          answered Nov 12 at 15:04









                          Max Koretskyi aka Wizard

                          47.8k20131239




                          47.8k20131239



























                              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%2f53262515%2fhow-to-get-a-component-element-provider-injector-within-its-node-definition%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







                              這個網誌中的熱門文章

                              Barbados

                              How to read a connectionString WITH PROVIDER in .NET Core?

                              Node.js Script on GitHub Pages or Amazon S3