简体   繁体   中英

window Opener Angular2

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>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM