0

I need to communicate a child window with parent window in Angular 2 I'm clueless, how to I can use window.opener to pass a parameter to angular 2.

In angular 1.5 I used something like this Accessing parent

In Javascript something like this

Parent Window

<!DOCTYPE html>
<html>
  <body>
    <h1 id="demo">parent</h1>
<script>
function parentFunction(myVar) {
    document.getElementById("demo").innerHTML = myVar;
}
</script>
  </body>
</html>

Child window

<!DOCTYPE HTML>
<html>
  <head>
    <title>fuente de múltiples elementos</title>
  </head>
  <body>
    <button onclick="window.opener.homeFunction('passVariable')">Click         me</button>
</body>
</html>
Hector Bayona
  • 97
  • 1
  • 2
  • 6
  • What's the problem exactly? If you're using `onclick` there should be no difference. if you're using `(click)` you have to use a function in your component to access `window`. – malifa Jul 04 '16 at 18:37
  • I don't know how to pass the parameter to the component, I need something to listen the child window. – Hector Bayona Jul 06 '16 at 04:10
  • One option is to define a service that is shared between the components. You can then set data in a property of the service class and later get the data from that property. – DeborahK Jul 08 '16 at 21:49

1 Answers1

0

Here is a nice answer https://stackoverflow.com/a/39280942/1904479. Detailing how this can be achieved in angular 2. Exposing a coponent method publicly so as to be accessed from a different source.

Kailas
  • 7,350
  • 3
  • 47
  • 63