DEV Community

nikolaof
nikolaof

Posted on

1 1

AngularJS communication between two components

Hi.

I'm writing an SPA using angularJS and so far I have created two distinct components for the app one called loginModal and the other one listFiles.

In the html I call them like

<login-modal></login-modal>
<list-files></list-files>
Enter fullscreen mode Exit fullscreen mode

On init of the loginModal component, I check if there is a valid JWT token stored and if not I ask for login. If the login is successful the modal closes and the JWT token is being stored. Along with the JWT also a string defining a directory path (for that specific user) is retrieved from the server.

Now what I want to achieve after a successful login, is to somehow trigger a method inside the listFiles component to make a call to the API using the directory string taken before.

Is something like this possible? Can someone provide me with some info resources on how to do such a thing?

Also, any other idea is welcome.

Thank you.

Heroku

Simplify your DevOps and maximize your time.

Since 2007, Heroku has been the go-to platform for developers as it monitors uptime, performance, and infrastructure concerns, allowing you to focus on writing code.

Learn More

Top comments (3)

Collapse
 
zilurrane profile image
Zilu Ramkrishna Rane

RxJS comes with concept of Subject.
You can look at below article for more details.
hackernoon.com/subjects-in-angular...
In our project we used Subject to pass value from One Component to Another.

Collapse
 
nikolaof profile image
nikolaof

Can this be used with AngularJS (1.x) ? Because I'm only seeing references with Angular2

Collapse
 
zilurrane profile image
Zilu Ramkrishna Rane

I never tried AngularJS(1.x) So, not sure about practicality of above solution here.
You can have a try.

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay