1

Are AngularJS apps treated as windows? Can you attach an eventlistener to them?

I am trying to conduct a proof of concept for whether an Angular app can make a no-prompt to a server and get the response back without affecting the host.

The best option I've come to is using .postMessage() to initiate a call to the server in a hidden iframe then having the host in the iframe .postMessage() the message back. I have been able to accomplish this with nested iframes but want to adapt this concept to an Angular app.

Is this possible?

user2958542
  • 331
  • 1
  • 8
  • 18
  • I'm really not sure what exactly you're trying to achieve, but regardless, angular apps are not treated as windows. What do you mean by "make a no-prompt to a server....without affecting the host"? – Sacho Jun 21 '15 at 18:04
  • @Sacho "No prompt request" refers to automatically making a request to a server and getting whatever response it gets and handling it. And the page that the app is on should **not** have direct access to what is happening within the app. That is it should not refresh, see any data, or anything. – user2958542 Jun 21 '15 at 18:13
  • @Sacho The app I want to have this functionality is bootstrapped onto a larger app. It is a component on the page. – user2958542 Jun 21 '15 at 18:16
  • "no direct access" is not a possibility without iframes - the security model for pages is pretty simplistic, there's no encapsulation between "apps"(or indeed any concept of such) - all javascript is executed as the same user. Without the security concern, it sounds like you're describing an ajax request. – Sacho Jun 21 '15 at 18:20
  • @vinayakj Thank you for the suggestion. However since the way websockets are structured, the server I am using doesn't recognize the connection therefore it doesn't work. Thank you though :) – user2958542 Jun 21 '15 at 18:23
  • @Sacho I am aware. However, I am asking if there's a way to translate my existing code which is nested iframes into an Angular app. I have already constructed the paths and ajax requests in plain JS and would like to know if it is possible to have this same relationship with Angular – user2958542 Jun 21 '15 at 18:25
  • @Sacho, my main concern is that if i post a message back to the parent and the parent has a listener for a different request that should be happening, i don't want to interfere. I want my app to only receive the messages it is expecting. – user2958542 Jun 21 '15 at 18:28

1 Answers1

0

Are you already seen something about $broadcast and/or $emit in AngularJS?

You can use those to handle events.

Working with $scope.$emit and $scope.$on

Community
  • 1
  • 1
Eric Douglas
  • 449
  • 7
  • 12