පෙන්වමින් පමණක්
0:02
S… Speaker 1 (113. Understanding the Hierarchical Injector)
In the last lecture we set up our account service and hooked it up in our app
0:06
S… Speaker 1 (113. Understanding the Hierarchical Injector)
and still our app seems to be broken.
0:09
S… Speaker 1 (113. Understanding the Hierarchical Injector)
If I click these buttons the status is not changed.
0:12
S… Speaker 1 (113. Understanding the Hierarchical Injector)
So somehow our code is not working.
0:15
S… Speaker 1 (113. Understanding the Hierarchical Injector)
Actually it's working correctly.
0:18
S… Speaker 1 (113. Understanding the Hierarchical Injector)
We're just using services wrong here.
0:21
S… Speaker 1 (113. Understanding the Hierarchical Injector)
In this specific case we're not using the service in the way we should
0:25
S… Speaker 1 (113. Understanding the Hierarchical Injector)
use it in our app.
0:27
S… Speaker 1 (113. Understanding the Hierarchical Injector)
What's going wrong?
0:29
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the Angular dependency injector actually is
0:33
S… Speaker 1 (113. Understanding the Hierarchical Injector)
a hierarchical injector.
0:35
S… Speaker 1 (113. Understanding the Hierarchical Injector)
That means that if we provide a service in
0:39
S… Speaker 1 (113. Understanding the Hierarchical Injector)
some place of our app,
0:40
S… Speaker 1 (113. Understanding the Hierarchical Injector)
let's say on one component,
0:42
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the Angular framework knows how to create
0:47
S… Speaker 1 (113. Understanding the Hierarchical Injector)
an instance of that service for this component and,
0:50
S… Speaker 1 (113. Understanding the Hierarchical Injector)
important, all its child components.
0:53
S… Speaker 1 (113. Understanding the Hierarchical Injector)
And actually,
0:54
S… Speaker 1 (113. Understanding the Hierarchical Injector)
this component
0:56
S… Speaker 1 (113. Understanding the Hierarchical Injector)
and all its child components and the child components of the child components
1:00
S… Speaker 1 (113. Understanding the Hierarchical Injector)
will receive the same instance of this service.
1:04
S… Speaker 1 (113. Understanding the Hierarchical Injector)
There are other places where we can provide a service too.
1:08
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The highest possible level is the app module.
1:12
S… Speaker 1 (113. Understanding the Hierarchical Injector)
We haven't done this yet,
1:13
S… Speaker 1 (113. Understanding the Hierarchical Injector)
but we will see this soon.
1:15
S… Speaker 1 (113. Understanding the Hierarchical Injector)
If we provide a service there,
1:17
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The app module does have a provider's array.
1:20
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The same instance,
1:22
S… Speaker 1 (113. Understanding the Hierarchical Injector)
and that's important,
1:23
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the same instance of the class of the service is
1:27
S… Speaker 1 (113. Understanding the Hierarchical Injector)
available in our whole app,
1:28
S… Speaker 1 (113. Understanding the Hierarchical Injector)
in all components,
1:30
S… Speaker 1 (113. Understanding the Hierarchical Injector)
in all directives,
1:31
S… Speaker 1 (113. Understanding the Hierarchical Injector)
in all other services where we maybe inject a service.
1:35
S… Speaker 1 (113. Understanding the Hierarchical Injector)
Yes, we can inject services into services.
1:37
S… Speaker 1 (113. Understanding the Hierarchical Injector)
I'll come back to this.
1:39
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The next level,
1:41
S… Speaker 1 (113. Understanding the Hierarchical Injector)
for example,
1:41
S… Speaker 1 (113. Understanding the Hierarchical Injector)
would be the app component.
1:43
S… Speaker 1 (113. Understanding the Hierarchical Injector)
There,
1:44
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the app component and all its child components do have
1:48
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the same instance of the service.
1:50
S… Speaker 1 (113. Understanding the Hierarchical Injector)
And this is true for any component.
1:52
S… Speaker 1 (113. Understanding the Hierarchical Injector)
So even if we have a child of the app component,
1:54
S… Speaker 1 (113. Understanding the Hierarchical Injector)
if we provide it on that child,
1:56
S… Speaker 1 (113. Understanding the Hierarchical Injector)
all the children of this child will have the same instance and the child
2:00
S… Speaker 1 (113. Understanding the Hierarchical Injector)
itself, but not the app component.
2:02
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The instances don't propagate up.
2:05
S… Speaker 1 (113. Understanding the Hierarchical Injector)
They only go down that tree of components.
2:10
S… Speaker 1 (113. Understanding the Hierarchical Injector)
The lowest level,
2:11
S… Speaker 1 (113. Understanding the Hierarchical Injector)
therefore, is a single component with no child components.
2:15
S… Speaker 1 (113. Understanding the Hierarchical Injector)
If we provide a service there,
2:17
S… Speaker 1 (113. Understanding the Hierarchical Injector)
this component will have its own instance of the service,
2:21
S… Speaker 1 (113. Understanding the Hierarchical Injector)
and,
2:22
S… Speaker 1 (113. Understanding the Hierarchical Injector)
well, it doesn't have any child components,
2:24
S… Speaker 1 (113. Understanding the Hierarchical Injector)
so this instance will only be available for this component.
2:27
S… Speaker 1 (113. Understanding the Hierarchical Injector)
And this will actually even overwrite if we were to provide
2:31
S… Speaker 1 (113. Understanding the Hierarchical Injector)
the same service on a higher level.
2:33
S… Speaker 1 (113. Understanding the Hierarchical Injector)
And that's exactly what we're doing.
2:35
S… Speaker 1 (113. Understanding the Hierarchical Injector)
So let's take a closer look in the next lecture.

මෙම පරිවර්තනය AI විසින් ජනනය කරන ලදී (ස්වයංක්රීය කථාව හඳුනා). දෝෂ අඩංගු විය හැක - විවේචනාත්මක භාවිතය සඳහා මුල් ශ්රව්ය එරෙහිව තහවුරු. AI ප්‍රතිපත්තිය

❤️ ආදරය STT.ai? ඔබේ මිතුරන්ට කියන්න!
සාරාංශය
මෙම පරිවර්තනය AI සාරාංශයක් ජනනය කිරීමට සාරාංශ ක්ලික් කරන්න.
සාරාංශගත කිරීම...
මෙම පරිවර්තනය ගැන AI අහන්න
මෙම පරිවර්තනය ගැන යමක් අහන්න - AI අදාළ කොටස් සොයා සහ පිළිතුරු දෙනු ඇත.