3

I have been working on an angular application. I have one requirement while where I show list of available tasks to user and clicking on a particular task, open a new window with the same AngularJS application code base, which will allow the user to make changes to the task. The application in new window will be independent and user can perform some actions. Once user closes the window, I need refresh the task list in parent application (parent window).

I am passing some data to child window, the data consist of some properties and one function,

var appData = {
                action: "edit",
                id: taskId,
                refreshTasks: refreshTasks
            };

Refresh task is a method in my one of the controller

I am passing the data to the child window in following manner,

var windowHandle = $window.open("http://www.example.com"); 
if(angular.isDefined(windowHandle)) {
     windowHandle.appData = (dataObj == null ? {} : dataObj);
     windowHandle.appData.isChildWindow = true;
}

Now we access the passed data in child window using,

$window.appData

Now when child window closes, I am invoking my passed function in following manner,

$window.appData.refreshTasks()

The above seems to work in Chrome and Mozilla but its not working in IE (8,9,10,11)

So I really wanted to know how I can call function from one angular application in one window to another angular application in another window.

Can you kindly let me know what is the correct way to do this ?

1 Answer 1

1

You can access the appData using window.opener:

window.opener.appData
window.opener.appData.refreshTasks()
Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for the answer. But still this does not work. Is it that I have to send data like below windowHanlde.opener.appData ?
the above mention codes will work if appData is global variable in parent window
Its not global variable. That is what my question is about, how can I call the function in one of my controller from child window.
so appData is defined inside a controller?
No AppData I form after opening window and assign it to the child window's reference windowHandle.appData you can see in my code above I have explained. But however I tried creating a global function in my parent window and tried calling it from child window like this window.opener.myParentWindowFunc() but this too does not work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.