initiating an event within a modal controller

I have a $scope.$on callback function in my mainController. It works perfectly whenever I call it from each controller, but when I call it from a modalController after opening the modal, it doesn't work:

define(['app', 'jquery'], function (app, $) {
    app.controller('MainViewControllerUser',
        function ($scope, $location, $rootScope, $interval, MainViewFactoryUser){
        $scope.$on('loadingPage', function (event, value) {
            $scope.chartLoading = value;
        });
}
});

//----------------------- end of main Controller

 define(['app', 'underscore'], function (app, _) {
        app.controller('advertisementController',
            ['$scope', '$location', '$rootScope', '$interval', 'toaster', 'advertisementFactory', '$modal',
                function ($scope, $location, $rootScope, $interval, toaster, advertisementFactory, $modal) {
                $scope.$emit('loadingPage', true);

    }
    ]);



  app.controller('addClientCrtl',
            ['$scope', '$modalInstance', 'toaster', 'advertisementFactory',
                function ($scope, $modalInstance, toaster, advertisementFactory)
    {
                    $scope.$emit('loadingPage', true);

    }
    ]);



   });

The

$scope.$emit('loadingPage', true);
in the advertisementController works well, but in addClientCrtl it's not working. It's worth mentioning that the modal controller is defined in the adviertisementController and called inside it.

Answer №1

Why not consider using $rootScope instead of $scope in this scenario:

$rootScope.$on('loadingPage', function ({
});

$rootScope.$emit('loadingPage', true);

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

Creating a javascript variable in c#

Currently, I am working on incorporating the selected index text from a DropDownList into a JavaScript string. My approach involves storing the text in a hidden field and retrieving it through C# to ensure the JavaScript variable retains its value even aft ...

What is the best way to manage the browser tab close event specifically in Angular, without it affecting a refresh?

I am trying to delete user cookies when the browser tab is closed. Is this achievable? Can I capture the browser tab close event without affecting refreshing? If I attempt to use beforeunload or unload events, the function gets triggered when the user ref ...

Can you explain the purpose and function of stub.callsArg(index) feature in Sinon.JS?

Confusion has set in as I try to make sense of this. According to the documentation: stub.callsArg(index) - This command prompts the stub to execute the callback function found at the specified index. For instance, using stub.callsArg(0); will trigger the ...

Instead of loading the HTML into the div, Ajax is now sending me the link instead

I have just begun working on a new laravel project and am currently working on the user profile page, which will include a sidebar with links like Portfolio, Account Settings, etc. My goal is to dynamically load each page into a div when a link in the side ...

Angular UI Router allows for the resolution of data before a state

When working on my angular sample route, I attempted to achieve the following: (function(angular){ 'use strict'; angular .module('appRouter',['ui.router']) .controller('routerCtrl',function( ...

What is the method utilized by Redux to store data?

I am currently developing a small application to enhance my understanding of how to utilize redux. Based on my research, redux allows you to store and update data within the store. In my application, I have implemented an HTML form with two text inputs. Up ...

Having trouble organizing a list of objects based on changing keys

Below is the implementation of a custom pipe designed to sort records: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'sortpipe' }) export class SortPipe implements PipeTransform { transfor ...

Waiting for POST request to be executed once data is inserted

This was a new experience for me; I took a break from working on the project for a while, and suddenly all POST routes stopped functioning. However, the GET routes were still working perfectly fine. After extensive debugging, I discovered that removing the ...

Troubleshooting: Issues with window.location.href and window.open within an iframe

Code Update <div> <button type="button" class="submit btn btn-default" id="btnSubmit">Submit </button> <button type="button">Cancel</button> </div> <script> $("#btnSubmit").click(function(e) { ...

Strategies for efficiently parsing JSON in HTML using AngularJS

I have received this JSON format and I am looking to extract the message and username fields. How can I achieve this? Also, I want to format the date in Y-m-d format. I tried using ng-repeat but couldn't print the data. Can someone please help me disp ...

How to Insert <ul></ul> After Every Other <li> Element Using Angular's ngRepeat

With my current setup, I have a list item (li) within a list (ul) and applied ngRepeart. However, I would like to create a new ul after every 2nd li. Is this possible with AngularJS? <ul> <li>simth</li> <li>aryan</li> < ...

The functionality of Angular bootstrap scrollspy is hindered when dealing with dynamically changing image content

I recently came across an answer that guided me to fork an example for implementing scrollspy in Angular.js. My goal is to populate dynamic content using a template that includes images. You can find the example here: http://plnkr.co/edit/OKrzSr Here are ...

creating images using express.js

Exploring the world of node.js and express.js is an exciting journey for me as a newcomer. I've been working on upgrading my front-end project with these technologies, and everything seems to be falling into place perfectly except for one roadblock - ...

retrieving the smallest and largest values from a date range selector

I have been implementing a date range slider following the guidelines from this resource. I successfully set up the slider according to the documentation, but now I need to retrieve the minimum and maximum values as the slider is being moved. I attempted t ...

Update the date on the AngularJS datepicker to today's date

When a button on my md-card is clicked, a modal opens up allowing me to select a date. Below is the code for this functionality: <!-- Modal --> <md-dialog aria-label="Date Picker"> <div class="modal-content"> <div c ...

jQuery - easily adjust wrapping and unwrapping elements for responsive design. Perfect for quickly undo

Within the WordPress PHP permalinks and Fancybox plugin, there are elements enclosed in an "a" tag like so: <a href="<?php the_permalink(); ?>" class="example" id="exampleid" data-fancybox-type="iframe"> <div class="exampledivclass"> ...

Is NodeJS Asynchronous: Has the callback been called twice?

I'm currently working with the Async module in Node.JS to manage my asynchronous calls. However, I've encountered an issue stating "Callback already called." Could someone assist me with resolving this problem? async.each(data['results&apos ...

Add attributes to the top level

<li class="page_item"><a href="javascript:">A</a> <ul class="children"> <li class="page_item"><a href="">1</a></li> <li class="page_item"><a href="">2</a></li> </ul> < ...

When attempting to send an archiver file in NodeJS, the request may become unresponsive

In my NextJS application, I am facing the challenge of generating a large number of QR codes at once, like 300, 400, or even 500, and then packaging them into a zip file for users to download. The following code snippet demonstrates how I achieve this usin ...

What do you believe to be superior: Vue UI design?

Scenario: Application managing multiple user roles. A view with extensive conditional rendering in the template. a) Is it preferable to have numerous conditional statements in a single view's template? b) Should separate views be created for each ro ...