How to get parent component data from child window in angular 8 using window.opener

1.9k views Asked by At

I have 2 pages in angular, page1 with a button, when clicked, it opens page2. So they are 2 different components. I must use window.opener to get page1 data in page2 because i am calling window.opener.page1Func()

In pure html and javascript, i can get data from page1func defined in page1.

page1

function page1func()
{
    return "xxx";
}

page2

var result = window.opener.page1func();

above is working fine in pure js and html, but how can i do this in Angular way? (angular 8 is what i am using)

Any clue would be helpful. Thanks.

1

There are 1 answers

0
Anusha kurra On

There are multiple ways to pass data from parent to child (pop up new window)

  1. Defining "window" component that will be rendered on a new popup window .Here is a working example of popup window component

  2. ngrx-store

  3. window.postMessage()

  4. session/local storage