Invoking a function from the main window within a child window specified in Angular

This issue is really frustrating me and I've been stuck on it for hours without finding a solution. I'm hoping someone here can help me out.

Inside my controller.js file, I have a controller that contains all the information about my page. There's also a button on this page that opens the same page in a new popup window. I'm attempting to call a function in the main window when the user clicks on a button on the popup page.

In my controller.js:

.controller('rackLayoutController', ['$scope', 'appService', 'rackLayoutService', 'siteService', '$location', '$log', '$sanitize', '$window', '$timeout',
function ($scope, appService, rackLayoutService, siteService, $location, $log, $window, $timeout) {

$( window ).ready(function() {
    function refreshPopout(){
        $(window).ready(function(){
            console.log("readyyyyy");
            setTimeout(function () {

                window.location.reload();

            }, 1000);

            });
        }
    });

    $scope.$on('updateRack', function () {
        console.log("BROAD 1");
        window.opener.refreshPopout();    

    })

When the user clicks the button, I trigger broadcast updateRack and while it does log the message correctly as expected, the function itself fails to execute.

The error received is :

TypeError: Object [object global] has no method 'refreshPopout'

Thanks

Answer №1

$( window ).ready(function() {
    function updateDisplay(){

The function updateDisplay is not accessible globally when you invoke it.

You can modify it like this:

$( window ).ready(function() {
    window.updateDisplay = function(){

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

Storing a boolean value in MongoDB as a string

const myObject = { school: true, address: false }; const myArray = []; myArray.push(myObject); updateSchool(myArray); function updateSchool(thisSchool) { $.ajax ({ type: "POST", url: '/update_school', d ...

"Escaping from the typeahead feature in Angular-UI Bootstrap results in the input field value becoming

Having some difficulty solving a particular edge case scenario. When I select a value from the dropdown of the typeahead using either the keyboard or mouse, the ng-model in the input field is populated correctly. However, if I type a few letters and then ...

Accessing a specific attribute of an object contained within an array

Currently, I am utilizing Vue.js in my project and have implemented a method that involves comparing values from two different arrays. array1: [{ name: 'test1', somevar: true }, { name: 'test2', somevar: false }] array2: ['test1 ...

Tips on invoking the ('keyup') function within an AJAX request's success callback

I have been working on implementing a live search feature that is based on JSON data fetched through an AJAX call. Here is the code I have been using, but unfortunately, it is not functioning as expected. function returnVisitors(){ let output ...

Adding a jPlayer on the fly

I've been working on a code snippet to dynamically add jPlayers through a function. Here is the code I have so far: function audio_player(audio, title, type) { var id = $('.audio').length; $('#audio').append('<di ...

Discover how to transform the ist date and time format to est with the power of angularjs

I need to transform the date from 5/3/2018 to Mon Mar 5 01:54:07 EST 2018 format using angularjs before sending it to the backend. ...

What is the process for updating the class of the target button?

I am new to using Vue and struggling to achieve a specific functionality. I have multiple buttons and I want to ensure that only one button can be selected at a time. Currently, I have tried implementing it with the following code: :class="isActive ? ...

What is the best way to connect and run my React front-end with my Express back-end simultaneously?

I'm feeling ambitious and trying to construct a basic React/Node/Express application from the ground up without relying on create-react-app. I've successfully developed a simple backend to send data to the frontend, but I'm struggling to und ...

Using javascript, retrieve the JSON values for each level

I need help using a recursive function in JavaScript to retrieve the last key value pair from a simple JSON object. Here is an example JSON object: { 'a': { 'b': { 'c': 12, 'd': 'Hello World& ...

When should you utilize child or nested states in AngularJS UI-Router?

I'm currently working on a large AngularJS application that follows the design of having one .html file per state. Each view is represented by a single HTML file, and I am avoiding including multiple HTML files per page. $stateProvider.state('fi ...

Processing Microsoft Office files with Node.js

I have a project underway for a web application that allows users to upload Microsoft Office Document files. Our current setup involves Node.JS with Express.js running on Heroku, which means I am unable to install programs like abiword or catdoc. Although ...

What is the method for showing the arrays following Json.stringify and Json.parse?

I've been facing challenges trying to redirect notifications from my mobile application to another page and store them as historical records. Despite my efforts in researching and experimenting with various methods, I have yet to achieve the desired o ...

Working with AngularJS: retrieving and displaying a property from a connected collection

I have set up two collections in Angular: app.controller('MainCtrl', function($scope, PieceService, TeamService) { PieceService.query(function(data){ $scope.pieces = data; }); TeamService.query(function(data){ $scope.teams = data; ...

What is the correct way to utilize the onclick() method while passing specific variables, such as an ID of a Mongoose Object Document, as arguments?

As I dynamically add rows to a front-end table based on data from a custom node.js API, each row represents a student with fields for Name, Class, Roll_No, and a button that changes color based on the student's specific value. The button code looks li ...

What is causing Vuejs to not recognize the status of my button?

I am currently developing a Vuejs website that allows users to jot down notes about meetings. Upon loading, the website fetches the meeting notes from the server and displays them. When a user adds new notes and clicks the "Save" button, the text is saved ...

Share the hyperlink to a webpage with someone else

In my SQL command, I have a unique feature that retrieves the complete URL value of the current page: [##cms.request.rawurl##]. This code returns the entire URL. I need to send this address to another page and load it into a special div called "load-fac". ...

Unable to dismiss my DIALOG component using onClick in REACT

Hey there! I'm feeling a bit frustrated trying to work with the DIALOG component in Material UI. My goal is to make a simple DIALOG component appear when I click on a bin Icon from the MUI library. Here's what I've tried so far: Setting ...

I can't seem to get the npm run dev command to work properly after setting up

After successfully setting up React JS with Vite and running npm i, I encountered an error when trying to run npm run dev: > [email protected] dev > vite E:\nasheednaldo\node_modules\rollup\dist\native.js:64 ...

Eliminate parameter from URL

Here is the URL I am working with: http://my.site/?code=74e30ef2-109c-4b75-b8d6-89bdce1aa860 My goal is to redirect to this URL: http://my.site#/homepage To achieve this, I use the following code snippet: import { push } from 'react-router-redux& ...

When I attempt to utilize the API, the JavaScript implementation of a <script src=...> element seems to interfere

Within one of my HTML files, I encountered the following line near the top: <script src="//maps.google.com/maps/api/js?key=apikey"></script> The API key is currently hardcoded in this file, but I would like to use a configuration option store ...