1

I am working on an app, similar to DHC by Restlet . I would like to be able to store headers (which are inputed by user, just like in Dev HTTP Client) in a cookie or something similar to have the possibility to "remember" which headers were inputed by the user like in Dev HTTP Client. I am trying to make this with $cookie and $cookieStore, but it doesn't seems to work well (on Chrome cookies aren't saved at all, and on FireFox they disappear if the browser is relaunched).

This is how it looks like (checkbox is used to save/remove header from cookies and plus - add new header):

enter image description here

Please, point me to the solution or provide some useful links / articles, provide your own thoughts! Every answer is highly appreciated and answered immidiately.

Thank you.

Filip
  • 3,002
  • 1
  • 26
  • 37
amenoire
  • 1,892
  • 6
  • 21
  • 34

1 Answers1

1

I'd say that using a module using HTML5 local storage would be a good idea; for example, using angularLocalStorage, you would inject it in your module (don't forget to include the cookie fallback)

angular.module("surveillance", ['ngCookies','angularLocalStorage']);

then bind a property to the local storage:

storage.bind($scope, "queries", {
    defaultValue:[{
                    "title" : "angularjs is used in this app",
                    "search" : "https://api.stackexchange.com/2.2/search/advanced?page=1&pagesize=25&order=desc&sort=creation&closed=False&tagged=angularjs&site=stackoverflow"
                }
            ]
    });

Now any change to the queries property of your scope will be persisted between calls. In order to see a demo, you can have a look at this page that i wrote that lets you keep favorite searches on stackoverflow (full source code: disclaimer i was just working on this when i saw your post while testing the app :) )

samy
  • 14,832
  • 2
  • 54
  • 82
  • Hehehe :)) I was looking for something like this. Thank you!:) You answer is useful, I will give at a plus. And if it'll help me make things done - I'll mark as a correct answer :) – amenoire Mar 27 '14 at 12:05