Inter-service/module communication on a widget interface

We are in the process of creating a widget screen that contains various widgets/modules:

  • Products: Displays a list of products
  • Product Details: Retrieves product details from the server when a selection is made in the "Products" widget.
  • Related Products: Retrieves related products from the server when a selection is made in the "Product" widget.
  • Compare: Performs certain actions on the server when the "Compare" button in the "Product Details" widget is clicked.

While this may sound straightforward, we are facing a challenge in determining how these components should communicate with each other. We aim for them to be loosely coupled, meaning that the "Products" widget shouldn't need to know about the existence of the "Product Details" and "Related Products" widgets. Additionally, some widgets may not even be visible on the screen at all times, requiring no action.

The only solution we have considered so far is using $rootScope.$broadcast and $rootScope.$on to handle events like "ProductSelectionChanged" or "CompareClicked".

However, we have encountered concerns regarding performance issues with $rootScope.$broadcast, as discussed here: What's the correct way to communicate between controllers in AngularJS?. Furthermore, the suggested alternative by Christoph using $rootScope.$emit is incompatible with IE8.

Should we stick with using $rootScope.$broadcast or do you have a better suggestion?

Thank you for your assistance!

Best regards, Michael

Answer №1

While there may be other solutions out there, I recently faced a challenge with communication between my components and the performance limitations of using $scope.$broadcast(). To address this issue, my team and I developed our own PubSub service that offers a simple and efficient way to communicate events with parameters.

If you're interested in trying it out, you can find the service here: custom-pubsub

Answer №2

One option is to utilize messaging as suggested above, although it may become cluttered with excessive communication. In our scenario, we encapsulate it within a RequestNotification control and establish some constant IDs (refer to RequestNotificatinService)

Another method involves defining an outer directive (e.g. containing common data) and referencing it in the inner directives (similar to how ngmodel is requested in a custom directive)

A great example showcasing how this concept operates can be discovered here:

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Dividing a string into sections and sending each section to a function

I'm currently facing an issue while trying to pass string objects to a function. The query string in the URL contains fields that are in a comma-separated string format with attributes of interest. I've stored the attribute names in the fields a ...

Is there a way to ensure uniform display of HTML form error messages across various browsers?

Recently, I completed a login form that consists of username and password fields. For the username, I used a text field with the type email, while for the password, I utilized a text field with the type password which requires validation through a regex pa ...

How can I refresh the information without appending it to the existing table using JavaScript and jQuery?

I am currently utilizing the pusher API and I am facing an issue where the data gets added to my table every time a new state is called. Instead, I want to update the existing data in the table without creating a new row every time. I only want to add a ne ...

Verify the user's activity status in the MySQL database using Node.js by checking the timestamp of their last login

I have a query regarding user activity and deletion from the database. I need to determine when a user last logged in to see if their account is inactive. Unfortunately, I am unsure of how to tackle this task or check for the last login time. If anyone c ...

What is the best way to empty a backbone collection in preparation for loading new data?

Hey everyone, I've been working on a Backbone application that involves adding and deleting or editing images. Currently, I'm using a router to navigate between different sections like the gallery and forms. However, whenever I make changes in th ...

Inconsistencies in Height Among JQuery Elements

I am encountering an issue with my datatable.js, where I am attempting to limit its height based on a specific row number, such as 4.5 rows. However, I am facing a problem with the row height (tr height). For example, when using the following method with m ...

Experiencing problems with lining up several circular items in a row

For my project, I am trying to showcase multiple circular shapes with percentages in a row, but I am encountering some issues. I attempted using a div with display flex, but it doesn't seem to be working as expected. Here is what I have tried so far: ...

What are the guidelines for storing an object on $rootScope in AngularJS?

While browsing through various tutorials on authentication, I came across a common practice of placing an 'auth' object on $rootScope. This approach is notably seen in the AngularFire-seed project created by the FireBase team. I've always b ...

Is it possible to integrate Express 4 standalone middleware into an Express 3 application?

While I am not yet prepared to upgrade my Express 3 installation to Express 4, I am interested in utilizing some of the enhanced components in Express 4, such as express-session and compression. I have experimented with implementing these upgrades and eve ...

Modifying an object's label based on a particular value using JavaScript

In my current project involving React.js charts, I am looking to organize data by month. In Django, I have set up a view to display JSON containing the total events per month in the following format: [ { "month": "2022-06-01T00:00:0 ...

Order Up: Vue Draggable Next feature keeps your lists in line

I need to maintain the order of two lists in local storage so that their positions are saved and retrieved between sessions. In my Vue 3 TS project, I am utilizing this library. Check out the code snippet below: <template> <div> <h3> ...

Troubleshooting CSS transition issues on ASP.NET Web Forms

Is there a way to make CSS3 transitions work in a .aspx page? I prefer Web Forms for designing forms and any suggestions would be helpful. The following is the code snippet from the .aspx page: <%@ Page Title="" Language="C#" MasterPageFile="~/Sit ...

React Component for Toggling a Click Event on a Select Tag

I'm currently developing a react app where clicking on a specific text triggers the display of a select tag with several items. However, I've encountered two issues: Upon clicking the text, the select tag appears on ALL list items instead of ju ...

Adjusting the color of the legend on a LineChart in ExtJS 4 on-the-fly

I've been trying to find information on how to modify the color of the x legend in a Line chart without success. Can anyone help me with this? I have included an image of the chart for reference. ...

Coloring the table upon selecting a checkbox using AJAX, JavaScript, and JSP

How can I adjust the color of the entire table (every row of the table)? Currently, I can only change the color of the first row of my table. Here is my color function in JSP: function changeColor(rowID){ var row = document.getElementById(rowID); ...

"Step-by-step guide on adding and deleting a div element with a double click

$(".sd").dblclick(function() { $(this).parent().remove(); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <table width="750" border="0" cellpadding="0" cellspacing="0"> <tr> <t ...

Develop a packaged version of npm kafka-node

I am just starting to learn about js module systems and building libraries. I am currently exploring the possibility of converting npm kafka-node libraries, which I believe are in Universal Module Definition format, into a bundled version of the library ...

Using jQuery UI autocomplete with special characters

Recently, I put together a simple jQuery example utilizing jQuery UI autocomplete feature. $(function() { //autocomplete $(".selector").autocomplete({ source: "getdata.php", minLength: 1 }); }) getdata.php: <?php if (isse ...

Stop automatic page refresh after submitting a jQuery post request

I've tried various solutions, but unfortunately, neither e.preventDefault() nor return false seem to be working for me. When I use prevent default ajax doesn't make post request. Even using $.post doesn't work as expected. Furthermore, addin ...

Setting a value to an anchor tag in AngularJS

A user is presented with a list of options (e.g. 1. Apple; 2. Banana; 3. Mango). They are provided with a textbox where they can input their desired option and then click "send" to proceed. Current Setup: HTML: <p ng-repeat="opt in objHistory.OptionI ...