Jogi masterfully condenses Angular’s architectural plumbing into a pragmatic toolkit that prioritizes functional utility over theoretical bloat. It is an essential, high-density briefing for any developer looking to navigate the complexities of component-based state management.
Deep Dive
Prerequisite Knowledge
- No data available.
Where to go next
- No data available.
Deep Dive
Master Angular Component Communication | Input, Output, ViewChild, Subject, Query ParamsAdded:
Fine.
So, Angular logical scenarios and problem solving. Now, with this series I'm taking some interview questions also and real-time project scenarios also.
Now, when you work on the real-time projects or in if you focus on the interview also, so component communication is very famous question.
So, with this they want to check how you will pass the data between one component to another component, right? So, that logic they will check. They want to check your RXJS also. Okay, do you know the subject and behavior subject or replay subject? How does they work?
Right? Again, routing also because from one component when you navigate to another component, you can pass the data with the query parameter also, right?
So, various ways are there how you access or how you pass the data from one component to another component based on the relation. Okay? So, I'm just taking an example of the existing project.
Now, in the existing project once I log in Just a minute.
Sorry. Okay. So, I'm logging as this one email ID 112233.
Now, let me show you the login component.
So, once user log in, I'm we are storing the data into local storage.
That is login.
Okay. So, once we log in, we are storing the data into the local storage and wherever we need the logged in data, right? So, in user service, we have a user service which is common and integrated everywhere.
So, in user service we have created a variable and there on the user service initialization we are reading the data and storing it over here. So, overall application wherever you need the logged in user data, we are accessing like that.
But, instead of this login is happening in one component and let's immediately after that in another component also you need the logged in data. So, this is one way to do it. You can create a normal variable in your service and then you can read the data into another component by accessing the service or you can store the data into your behavior subject also. So, so many applications are there. Means again, it varies to different different project that someone will store the logged in data into service kind of like this or they will create a function and in which will return the logged in user data or they might store the logged in user data into behavior subject also, right? Why behavior subject? Because it doesn't matter the component was there at the present at the moment or not, it should receive the data, right? So, what we can do? In my this service, I'm creating a uh log sub behavior subject to store the logged in data.
logged user. I'm adding a name like behavior subject so that we can identify.
behavior subject What type of data I'm going to store?
So, I have created class for it so that this type of data we are going to store.
New behavior subject. So, when we talk about behavior subject like we can do the initialization.
user model Right? It needs that initialization.
So or now it's a class, right? So, let's provide a new user model.
Okay? So, I'm just initializing my behavior subject.
Now, when you log in, immediately once you get the login data in result.data, you get the actual logged in data. So, that you will store into your behavior subject. So, this.
your user service.
logged user behavior subject.next and you will store the logged in user data. So, res.data I'm storing it over here. So, once user log in the logged in user data you are storing into the behavior subject.
Now, so many times when you are in the interview, they are asking you question he after login you are getting the token. Where you will store that token?
So, we answer like session storage or local storage. Sometimes we say cookie also. Still, they won't be satisfied.
So, if they are not satisfied with these three way, you can say he I can store that in a behavior subject or subject.
And whenever I need the data, I will listen to it and then I will use it.
Right? Because we are working on the browser technology. We have to store it somewhere. Either on your code level or on the browser level. Somewhere you need to store.
Right? So, this is also one of the ways how you will store the data.
Okay? Now, after the login I'm storing the data into my behavior subject. Now, let's say in header component, that is where my navbar is.
So, in my header component, here I have to show the logged in user data.
Currently, I have done that with that variable. So, in header component you can see on the page load I'm reading the local storage data. Means that and I'm putting it over here. So, instead of this now, I can access directly the subject behavior subject what I did. Right? So, user service is already injected over here. So, here what I will do this.user service.my behavior subject.
dot subscribe round bracket result. What type of data I have stored, I know. User model.
And that I will store into this variable over here.
is equal to res.
I will add debugger everywhere so that we can understand the flow.
Here.
Then after login also I'm adding a debugger.
Save.
Let's save.
Let's check.
So, farmer one 112233.
Let's check it now.
Let me make it in line.
So, on click of login, API call will happen.
Wrong credential. Why?
Oh, wait. It is going local. Let me change it to the deployed one.
Local API is not running so I'm using the online now.
So farmer one 112233.
I will enable debugger on click of login.
So, I got the response. So, if you check the res, we got data over here, the logged in user data. Now, that whole data I'm storing into my behavior subject by using next property. So, once you continue immediately you can see in header component subscribe got executed. So, from login component you store data.
Means see, it's a component communication. Something is happening in login component as soon as that event trigger, you want to notify header component that user is logged in. So, see in the login component you stored some data. Now, in the header component you are able to read that data.
Right?
So, immediately this logged in user data is visible.
So, this is one way of component communication. Now, the login component and the header component doesn't had any relation. They were not parent and child.
Guys, don't use this.
Okay? So, my header component and the login component were not having any parent-child relationship. So, whenever you don't have parent-child relationship, so what you do? You can take help of subject and behavior subject. Again, the based on the scenario. Like if you need to access the data when it was emitted, you will go for a subject. If you need uh it should maintain the history also like after some time your component is coming to the DOM, still it should receive the data, you go for a behavior subject, right? The basic difference between subject and behavior subject.
According to the scenario, we use it.
Right? So, this is one way.
Now, next one will be Let me go to farmer component.
Sorry.
Products.
Wait.
I'm logged in, right?
Something is wrong.
I did the log out or what?
Farmer one 112233.
Because earlier the test was farmer product. Okay.
Now, here Okay? So, now once user create successful product, okay? We have to show some model pop-up or let's say some alert box we have to show. Normally, we go for that alert box. So, instead of alert box, we can create a reusable component and there we can show something uh you know, bootstrap alert box something.
So, bootstrap Where is bootstrap alert?
Okay.
Okay? Now, whenever you do the API call, either API call is success or error, we have to show whatever the uh alert or the success messages, right?
So, now currently we have used Let me see.
Farmer product.
Okay? So, see. We are using the normal alert box. So, instead of this normal alert box, what I want, I want to show this alert box where somewhere over here after uh above somewhere place we will find out and here we have to show that you whatever the API call message is there. A product was successfully created or there was some warning or API failed something, right? So, we create a reusable component, okay?
Let's create a quickly. This is my alert box.
So, over here reusable component. I'm creating a new component over here.
In normal application, instead of uh this alert box, we use toaster, right?
So, currently in this project, I didn't install any third-party library.
So, alert box we will use.
So, created component. Now, our alert box HTML will go over here.
Now, this is the our reusable component which will be there. Now, we will have three types of alert. Let's say success, error, and warning, right? When you do the API call, API call return at least three statuses. Either API call will be success or it will fail or it will return some warning. API call is success, but something warning is there. So, we will go with three. So, different classes are alert success then alert danger. For error, it will be danger and third, it will be warning.
So, these are the three possible colors we have. Let me show you to what here also.
See, this is success for green.
This is warning, the yellow, and the red is the danger. So, these three types of alerts we are going to have. Now, how many inputs we can have, right? So, if you check the HTML first what type of alert it is, so that alert type we will need.
Here, either it is success or error or warning and the message itself. So, three input we will need. Let's quickly create those.
At the rate input round bracket alert type. It will be again string type of data, right? Empty.
Let me copy paste quickly.
Alert title then alert message.
Okay? So, we have three input. Now, based on the alert type, in alert type we are supposed we will uh we will accept either uh success, error, or the warning, right? So, this if alert type string or let's strongly type.
S U double C, success or error or warning.
Okay.
So now, based on the alert type, we have to add these three different classes, right? So, uh one way is by using property binding you can add a class. Another way is, but now here we don't have either or. We have three different classes for three different condition. So, here you can use the other way where we can have multiple classes. So, ng class ng class I will import.
Whenever you have multiple condition and according to the multiple condition, different different classes you have to add. So, this is the way what normally we use.
ng class equal to curly bracket.
First class name. So, first class is this.
This class you need to add then condition. What will be the condition when you have to add this card? So, alert type equal to equal to what three possible values?
It will be success.
So, see this class will get added if this condition gets satisfied.
Comma second class, its condition. Second class will be this.
Its condition.
It will be error.
Again comma, third class and condition.
Alert warning, this is your third class and the condition of it will be equal to equal to warning.
Okay?
So, based on the alert type we pass from the parent component, it will add the dynamic class. Then here, just a normal interpolation.
Alert title and here alert message.
Alert Okay? So, this is our reusable component ready.
Now, let's say if we talk about this particular component where we are creating the products.
Okay? So, here where we can show it.
Okay? So, after this small text, I will show this.
So, after this paragraph I have hyphen alert.
We have to import as we must be added automatically.
Okay? Alert has been added. Now, this parent parent component is your farmer product. From this parent component, you have to send the data to the child component. So, this is component communication. If you have a parent-child relationship, this is one way, right? So, when we talk about component communication, there are multiple there are two possible ways.
One is if you have if the components are having parent-child relationship by using input and output or by using your view child also. But in view child, you access the data, right? From the child component. So, first let's complete this, then we will see that.
Okay? Now here we need to pass the three parameters like uh alert type, alert title, and alert message. So, instead of creating three variable, what we can do, we can create a normal object. So, alert object colon any.
Like this. Now, here we can have alert type colon empty alert message colon empty alert What was the third one?
Title.
Okay? So, this object is created. Now, whenever you are doing the API call, either it is fail or success, right?
According to that, you have to set the values to this object.
Okay? So, this is my API call. So, this is my success block, right? If it is success, what you will do? So, this dot alert object dot alert type alert title or let's reinitialize complete thing again properly.
Why it's not okay? We did We have gone with any, so it is not suggesting anything.
Fine? So, alert type, let's say it is success.
Message product listing success and alert title success, okay?
This is for success. If it is in the error, right? So, error alert title also same and let's say from API you are getting the error, right?
So, you can extract that like if your API is returning specific message, so that also you can pass it over here.
I'm not sure like my API is returning something or not. So, let's pass static message like error while saving product.
Okay? So, we according to the API call, it is either it is success or error, we are storing different different data into this object. Now, this variable this object we will pass it over here.
So, why instead of creating three different variable, create an object and pass it, right?
Alert message, alert object dot I don't know here also it won't suggest now.
Alert message. That's why we create class and interface to strongly type everything.
Then alert title alert message dot same property we have, right? Alert title and third one is type.
Okay?
So our reusable component is ready.
Whatever that parent component expect, we are passing it.
Let's give it a test.
Wait, something and huh.
Now, by default it should not be visible. See, by default also it is coming.
Alert box is coming. Nothing is coming visible, but wait.
Alert and strong is coming. One div is missing, right?
One div is missing.
Okay, correct only.
But alert is there.
Yeah, let's give it a test. Okay? So, by default this should not be available.
We should control the like e once API call is success or error, when we have to show it. That we should control. So, we can create a variable and that will decide we have to show it or not.
So, or we can use this variable only.
Because in this variable, if the alert type is empty, we don't have to show it.
If the property any property will have the value, means we have to show it. So, like that we will do. So, instead of creating one more variable, we can use the same logic. So, if if this property alert type is not empty, not empty, then only we will render our alert component.
So, Okay? So, by default that alert component is not rendered now. Now, let's try to create.
So, why it's not expired or what?
Why it's not working again? I don't know.
Farmer only.
I'm logged in as Peach 19.
Okay.
So, now over here, let's say I'm creating capsicum. Let's say up till something available quantity 5 6 kg.
Available by date next Thursday.
Status available.
Now, on click of save, let's add a debugger into our API call also.
Product component name farmer product.
1 2 3 farmer in our top tiers.
Yeah.
Our save and the error block success and the error block.
On click of save now.
Okay, API call is success. We got the data. Now, we are storing that into our object. The details success, error, whatever, right?
And this object when then we are passing it, means in HTML we have used this object only to show and hide. Right? So, our alert box should be visible.
See, success product listing success.
Right?
If the error is there, if it goes to the error block, let's mean what we can do to fail the API call, I will make the I won't pass the exact object. I will pass the empty object. Okay?
Let me break over here.
I'm doing now.
In service, I will pass the empty object.
Here, I will pass the empty object. Okay? So, my API should break. I will get 400 invalid body.
Let's check.
It doesn't matter what I pass now.
On click of save, check payload. Okay, this error is coming from my interceptor.
So, see error block got executed. And in the error block, we are setting some different data into our error object.
We'll see.
Getting it? So, according to what data you are passing, your component is displaying that much information. Okay?
And again, after some set time out, you can reset this message also, because you know, whenever you work on application, your toaster or something gets visible for some particular time. So, you can use set time out, and you can again reset your object so that this will be right. So, product component product component is our parent component, and this is the child component. So, from parent to child, right? With the help of input and output. And again, vice versa. If from child you want to get some data to the parent component, you send it along with the output. So, this is your one way of doing communication by using input and output. Other ways, if you don't have the parent-child relationship, your subject or behavior subject, and then you send the data across the component.
Now, third way is view child.
Now, view child we can categorize as the uh way of component communication, because when you create the view child of the component instance, you are able to access the data. So, whatever data you have in child, let's create that.
So, in farmer product component, here we are accessing here we are using alert component. So, let's create a view child for alert component.
So, at the rate view child.
What view child you are creating? Alert component view child you are creating.
Okay?
Alert component instance.
Data type will be again alert component itself.
We cannot initialize it, so not. Okay? So, we created a view child.
Now, let's say when we save, after save, after some time I want to access the data.
Like let me undo the code what we did in service, otherwise the page will break.
Control Z, so it will pass the object whatever we want to pass. So, now my success block will execute. Now, here in set time out, or immediately over here also, I want to check what data I'm going to get in my uh what the in my alert component I have three variables.
Those are input, but nothing but variables also, right? Alert type and message. So, I can check that data over here.
Values is equal to this. dot alert component instance. dot So, all the component from your child component you will be able to access from over here. All the properties, whatever you have in your child component, you will be able to access it. See now over here, debugger.
Okay, on click of save.
Now, here you can see alert component.
Wait, how come alert component is?
Okay.
Now, so we faced an issue. Your view child is coming undefined. Why it is coming undefined? See, is your alert component visible?
Right now, no.
Because this variable value get changed. If the condition of the visibility is like in this property in this object, this property is not empty, then only. So, my alert component is not rendered yet, and you are trying to access it. So, by default obviously it will be undefined, right? So, we have to read that into after set time out. We'll let's give it some time, then it will render.
Let's say after 2 second we will try to access the value.
Then it will be rendered, and our view child won't be undefined.
This I will add it over here.
Save.
So, my alert component is visible now.
After 2 second my set time out got executed. See, now the view child has the data. So, whatever the variable, whatever the data you have in your child component, you are able to access.
Okay? Now, we this is just an example.
Why we will access why we will access data from the child component into the parent component? Consider you have a very big form.
Okay?
You have a very big form. Let's say here you have some button. Where is master?
Let me log in as super admin.
In super admin, we have something like that.
Admin.
Master component. So, here you can see we have two tabs, role and category. If I click on the particular tab, let's say particular component is getting rendered. If I click on this, particular component is getting. My parent component is master component. On in master component, I'm rendering role component and the category component.
So, now let's say here at the top you have to show how many records are there in role, and how many records are there in category in the parent component. So, this API call is happening in your child component. So, by creating the view child of it, you can access how many, you know, array.length is there. So, you can access that, and you can show that value will over here.
Getting it? So, consider this section is in your parent component. And here you have a requirement that you have to show, you know, let's say total category something. And just like that here, total roles. Okay? Now, category component is different, right? And your role component is different.
Okay? So, from both of the component in both of the component, you are making the API call to get all category and get all role. So, once that data is there, by using the view child, you will be able to read the data from child component, and then total you will show it over here something.
So, this is that example how we can why we need to create a view child of child component also, and how we extract the data.
Okay? This is the real time scenario what you can understand.
So, this is another way. So, subject behavior subject is one way, input output is another way, right?
View child is third way. One more way is while navigation, you know? So, if you have a query parameter, means you have a component with which accept to query parameter. So, let's say you have a list component where you just have a list.
But on click of edit, you are navigating to a different component. So, while navigating, you will pass something like this. Let's say edit product {slash} 0 or 32 or something.
So, this is how we send the parameter also. So, while routing, you can pass the data along with your query parameter. And then you read the data by using activated route {dot} params and then you subscribe to it and you get the data.
Right? So, these are the four ways that are there by which we can achieve component communication.
According to the relation, if parent-child relationship is there, input-output and view child.
If parent-child relationship is not there, subject behavior subject or the routing.
So, these are the four different ways how we achieve component communication.
Fine?
Yeah. Anyone having any question now?
This is interview question, so you should know and even though you don't get the chance to implement everything in your company's project, create a personal project and implement over there.
But if you have it already done it properly in your project, then you will feel more confident. And again, if you are using it while day-to-day work, so while doing the interview preparation, you don't have to again waste the time to learn that because you know it. You are using it, so you will be confident while answering.
Right? So, those people who are actually using it, their answer will look different. And if you have just by heart the answer, your answer will look obviously will look different. Okay?
So, have it practical ready if you are giving interviews.
Clear, everyone? Anyone having any question?
Okay.
Fine. So, I'm going to record a couple of more scenarios today. I will share half an hour before. Like filter pipe or you know, server-side pagination, something I will pick up whichever API I have been ready.
And we will or stepper also, something we will check.
Okay?
I will share the details in group. You can join it again.
Fine. Thank you all. Thanks for joining.
Related Videos
Agentforce NOW AMA: Build with React and Salesforce Multi-Framework
SalesforceDevs
490 views•2026-05-28
How agent o11y differs from traditional o11y — Phil Hetzel, Braintrust
aiDotEngineer
450 views•2026-05-28
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











