Search code examples
javascriptangularjsangular-cookies

making cookie name configurable


I am using angular ngCookies to read cookies. At present I am using this line to read cookie

$cookies.MYCOOKIE

The problem is that here I have to hard code cookie name, I have different cookie name in test/prod environment, but not able to find a way to read cookie from a variable.

Can someone please help.


Solution

  • In JavaScript everything is object and to access object property, you should use for example $cookies[variable_name].