0

Is it possible to send AngularJS scope data to a new Popup Window?

I am making an API section (Example JSFiddle), and while the user can look at the items expanded out my client was wondering if it would be possible for me to allow a user to push an API version (i.e Accounts 1) to a new window in case the client wished to compare some API's side-by-side.

So my question is, is there any way to utilize the (Open in new tab) in my Example JSFiddle, to push its containing data to a new pop up window? I would not need to bind it anymore, simply shove it out to a new window for viewing-only.

Keep in mind that for the JSFiddle I manually entered information for the API versions rather than plugging in my AngularJS. All the "Stuff" are {{AngularJS_variables}} in my actual application.

I feel like there should be a way to push some data to a new window, but at the same I feel like that wouldn't be possible due to my scope no longer existing outside of the parent window.

1
  • Can you pass the variables on the query string, possibly encoded? Commented Feb 17, 2015 at 2:58

1 Answer 1

1

Could you not store your data in localStorage (or sessionStorage) then read it from your new window?

something like this:

//handler for link
$scope.openWindow = function () {
    sessionStorage["myData"] = angular.copy($scope.myVars);

    window.open("myurl.html") //or a better way to open in a new tab...
};

Then your new page would just need to read the data

var myVars = sessionStorage["myData"];
Sign up to request clarification or add additional context in comments.

4 Comments

Hello! I have never used this before! :) Do I need any additional ngvalues for this? Or will plugging it into the Angular controller work off the bat? Also, is this meant for a blank .html template, that I just inject this var myVars into? Thanks!
sessionStorage has nothing to do with AngularJs. It's native JavaScript and is shared between windows (under the same domain). So you are just copying your JavaScript obj from one page, storing it in a common place (sessionStorage) then reusing it from your new page. so you could just set a $scope var like $scope.myVars = sessionStorage["myData"] and use it in your controller or view.
Okay! I shall give that a shot. Quick side question. If I am able to safely give a session a "token" is that a good way of authentication or no? If so, do you have a link to a guide on how to safely do this using that session variable? I just need to protect a single page. Thanks!
I guess you could authenticate this way (Although I wouldn't do it)... however you should encrypt your data. It can be seen from the web inspector and also modified.

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.