wangzixi-diablo / Spartacus-learning

record questions raised during my study
0 stars 1 forks source link

Magic: how the injected service is instantiated by Angular framework? #1

Open wangzixi-diablo opened 4 years ago

wangzixi-diablo commented 4 years ago

I have learned how to inject the needed service via component constructor like below:

image

that means within the scope of my component, I can use this.currentProductService to use the injected service.

However I am more curious about how the injected service is instantiated and passed into the constructor of my component, then I check the callstack in debugger:

question1

when I click the stack "MyOutletsComponent_Factory", the debugger directly navigates to line 19 and highlight it.

image

This makes me quite confused. Now what I see is still my-outlets.component.ts, but not so called "MyOutletsComponent_Factory". Where is the actual "MyOutletsComponent_Factory"?I cannot find it in chrome debugger.

Question 2

Then I check the outer stack, getNodeInjectable. I know it belongs to Angular core, but still I try to find currentProductService but failed.

image

I guess the l in lView means "logic", right? But how about "t" in tData? What's it meaning?

image

Since I cannot find my currentProductService instance in the code below, how is it technically passed as an argument into my component constructor?

 value = lView[index] = factory.factory(undefined, tData, lView, tNode);

I know this question might not be related to Spartacus development, but just curious about the magic behind it...