Get Angular events in the proper order

I am currently facing challenges with event handling in AngularJs. In my service, I send out events using the following line of code :

 $rootScope.$emit("FNH."+this.status, flowNodeHelper);

When receiving the event in service "S1," I handle it as follows :

    $rootScope.$on('FNH.READY', function(event, flowNodeHelper) {
        flowNodeHelperService.setActive(flowNodeHelper);
    });
    $rootScope.$on('FNH.ACTIVE', function(event, flowNodeHelper) {
        flowNodeHelperService.setCompleting(flowNodeHelper);
    });
    $rootScope.$on('FNH.COMPLETING', function(event, flowNodeHelper) {
        flowNodeHelperService.setCompleted(flowNodeHelper);
    });
    $rootScope.$on('FNH.COMPLETED', function(event, flowNodeHelper) {
        flowNodeHelperService.setClose(flowNodeHelper);
    });

Similarly, in a directive, I handle the events in the same way:

     $rootScope.$on('FNH.READY', function(event, flowNodeHelper) {
           console.log(flowNodeHelper + " status is ready");
      });
      $rootScope.$on('FNH.ACTIVE', function(event, flowNodeHelper) {
         console.log(flowNodeHelper + " status is  active");
      });
      $rootScope.$on('FNH.COMPLETING', function(event, flowNodeHelper) {
          console.log(flowNodeHelper + " status is completing");
      });
      ...

However, I noticed that the order of event reception differs between my service "S1" and the directive. How can I ensure consistency in event order between the two?

Answer №1

It's odd, but I found that it functions properly when I include this code snippet for every instance of calling flowNodeHelperService in section S1:

$timeout(function() {
     flowNodeHelperService.setActive(flowNodeHelper);
}, 1);

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

Tips on converting comma-separated values into HTML table rows using <tr> tags

JSON Data { "catalog_name": ["Sistem Autodownline ", "Karipap Pusing Ayu"], "price": ["100", "8"], "qty": "", "qty2": ["", ""], "total_qty": "", "total": "", "mem": "10", "email_2": "", "ic_add": "890527-08-6136", "c ...

Obtaining Data from an Array with Reactive Forms in Angular 4

Just starting out with Angular 4 and trying to figure out how to populate input fields with information based on the selection made in a dropdown. <select formControlName="selectCar" class="form-field"> <option value="">Choose a car&l ...

Encountering an issue with a class component stating that "this.setState is not a function

I am currently learning React JS and encountered an error when calling my first API in React. I keep getting the message "Unhandled Rejection (TypeError): this.setState is not a function." I have been trying to troubleshoot this issue on my own but haven ...

AngularJS allows users to easily navigate between different web pages by using tabs

I have created this Angular JS code to display tabs that open specific URLs when clicked. Can someone please assist me with making the tabs functional? <html ng-app="blp_tabs"> <head> <script src="http://ajax.googleapis.com/ajax/libs/angula ...

Adjust the start and end dates of the Bootstrap datepicker according to the chosen value

I am looking to dynamically set the startDate and endDate of a Bootstrap datepicker based on the value selected in an option form. For example, if I select "Boby" from the options, then the datepicker should be configured with startDate = 2016-10-04 and e ...

Can you explain the distinctions between Vue JS and React JS?

As I delve into learning Vue Js and React Js, my search for a detailed comparison between the two on Google left me unsatisfied. I came across resources answering the singular questions "What is Vue js?" and "What is React Js," but none that directly comp ...

The angular ui-router logout state fails to redirect to the login page unless the page is refreshed

After clicking on the logout link, I want to trigger the logout method of the AuthService to clear cookie data and then redirect the user to the login page. However, this process doesn't seem to be working as expected. The page stays on the /logout p ...

What is the best method for saving and accessing a user-entered date using session storage?

https://i.sstatic.net/I8t3k.png function saveDateOfBirth( dob ) { sessionStorage.dateOfBirth = dob; } function getDateOfBirth() { document.getElementById("confirm_dob").textContent = sessionStorage.dateOfBirth; } function pr ...

Listener document.addEventListener (function() {perform the function as shown in the illustration})

Currently facing an issue that I'm struggling to resolve, attempting to execute a code snippet from the ngcordova website without success. While using the plugin $cordovaInAppBrowser.open ({... it generally functions well until the inclusion of the ...

I'm experiencing an issue where my drum app element does not refresh after performing an action dispatch

Struggling with my React/Redux drum app, I'm at a roadblock with the final component that should update with the selected object's ID through an action dispatch. It baffles me why the element won't reflect the changes even though I've c ...

jQuery fails to make a POST request when the content type is set to application/json

I am utilizing jQuery version 1.10.1. My goal is to execute a POST request with the content type set to application/json. The code I have implemented is as follows: $.ajax({ type: "post", url: urlBase + "user/search", contentTy ...

"Empty array conundrum in Node.js: A query on asynchronous data

I need assistance with making multiple API calls and adding the results to an array before returning it. The issue I am facing is that the result array is empty, likely due to the async nature of the function. Any help or suggestions would be greatly appre ...

What is the best way to loop through an object and show each item in its own row?

My goal is to loop through an object where each item has a type property. The objective is to iterate through the objects and display them in rows based on their type. Currently, it looks like this: I aim to have Frontend, Backend, and UI displayed on se ...

"Creating a cohesive design: Using CSS to ensure the navigation background complements

I am working on a project with a horizontal navbar that I want to stay fixed while scrolling. The main window has different colored divs as you scroll down, and I would like the navbar to match the image of the main div while scrolling, creating a looping ...

When running "npx create-nuxt-app" followed by "npm run dev", an error occurs stating that there

Recently, I started using Nuxt and initiated my app with npx create-nuxt-app my-app, setting the parameters as follows: Project name: client Programming language: JavaScript Package manager: Npm UI framework: Tailwind CSS Nuxt.js modules: Axios - Prom ...

Changing Images with Button Click in Javascript

I am facing an issue with my buttons that should swap images once clicked. The first two buttons work perfectly, but for the third and fourth buttons, the images do not disappear when clicking another button. Below is the current code in the document head ...

Retrieve the maximum numerical value from an object

My goal is to obtain the highest value from the scores object. I have a global object called "implementations": [ { "id": 5, "project": 'name project', "scores": [ { "id": 7, "user_id": 30, "implement ...

Adapting npm scripts with Node.js based on the current context

Can you set up package.json to execute a different npm start script depending on the context? For instance, I want to run DEBUG=http nodemon app.js during development. However, I prefer to run node app.js in production. ...

Create a new JavaScript object by parsing JSON data

I am looking to achieve the following: var my_data = { x : 'orange', y : 2 } function object(data){ this.x = 'banana'; this.y = 3; this.z = 'default value'; } once I have executed: var new_instance = ob ...

How to use Javascript, HTML5, and AngularJS to display and print a PDF document within a

I have a situation where I need to load a Base64 encoded PDF as a String from my server into JavaScript in my client application which is built using AngularJS and HTML5. The structure of my HTML code is as follows: <div id="printablePdfContainer"> ...