问题标签 [angular-cookies]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
783 浏览

angularjs - 使用 Angular 1.2 在 cookie 中设置和获取对象

我正在尝试在 cookie 中设置用户属性。登录时,运行以下代码:

记录的数据包括配置文件对象,所以我假设它也被放入 cookie 中。

加载应用程序时,我会查找带有以下内容的 cookie:

这仅返回用户对象,没有配置文件对象。我在这里做错了什么?

0 投票
1 回答
1073 浏览

angularjs - $cookieStore 不为方法的另一次迭代保存数据

我有一个应用程序,其中我为数组(configurationsArray)中的每个项目(配置)设置了复选框。我要实现的是在选中复选框时将配置添加到 cookie 存储中

这是我的代码

如果你最后看到我尝试获取我推送到 cookieStore 中的东西,它工作正常。

但是,当检查另一个复选框并再次执行该方法时,我看到开头返回的值具有一个空数组。我在这里做错了什么?任何指针都非常感谢。

0 投票
1 回答
905 浏览

javascript - 角业力测试 $.cookie

我的注销功能向注销 api 发送请求并清除所有 cookie,从而有效地结束会话。它工作得很好,但是当我在测试中运行该函数时,我得到:

我知道这是从什么时候开始的,在注销功能中,我尝试通过运行来清除所有 cookie:

谢谢参观!其余代码如下:

控制器

测试

0 投票
2 回答
7633 浏览

angularjs - 如何解决angular js中的cookieStore未定义错误?

在这里,当我单击 storeAreaInCookie 这将导致城市的纬度和经度时,我必须将这些结果存储在 cookie 中,并且需要在我想在我的网站中使用的任何地方使用。但是当我尝试使用此代码时,它不会存储cookie 并在控制台中说未定义 cookie 存储。我该如何解决这个问题?

0 投票
2 回答
6974 浏览

angularjs - Send a cookie in http requests from frontend to backend with Angular

I am developing a web-application using AngularJS.

The application is realized with:

  • a frontend, a component without logic, that simply queries a backend many times, in order to receive from it all the needed data;
  • a backend, containing many RESTful services, and each of them returns data to the frontend (if the frontend calls it).

In my frontend, in the main controller, I create a cookie using $cookieStore, in this way:

Now, I want to send the information of this cookie to the generic backend service that I call. For example, one of my call has this form:

How can I send the cookie? Thanks in advance.

0 投票
3 回答
30374 浏览

angularjs - 使用 AngularJS 创建 cookie

我尝试使用下面的代码来设置 cookie:

我更新到 Angular cookie 的 1.3.14 版本,我知道有一个重大更改,但是我现在应该如何编写上面的代码?

运行上面的代码我得到这个错误:Error: $cookies.put is not a function


更新:我必须在 2 个文件中执行此操作:

0 投票
1 回答
763 浏览

angularjs - 角度 Cookie 不起作用

我正在使用Angular v1.3.10并且我正在成功设置 cookie。当我在做$cookieStore.put(key,value)然后$cookieStore.get(key)我看到我添加的对象。

当我刷新页面并做$cookieStore.get(key)我得到未定义的。

知道为什么吗?

0 投票
1 回答
2709 浏览

angularjs - 在angularjs中设置一个cookie然后路由到一个新页面

Angularjs 版本 1.3.15

我已经在我的页面“A”上使用 $cookieStore.put 设置了一个 cookie,现在希望将用户重定向到新页面“B”以使用该 cookie。我的问题是

如何将用户重定向到以 Angular 定义的已知路由,从而导致整个页面加载,这将读取 cookie 标头并允许我访问我的 cookie?

这是我发现的唯一有效的方法:

但是,它会导致双页加载并且很糟糕。一定有更好的方法。

提前致谢

编辑:

页面“B”正在使用使用指令的不同控制器,但我正在 Chrome 中查看“资源”选项卡 - 这就是我看到浏览器尚未看到 cookie 的方式。我希望在以下位置查看 cookie 的指令:

0 投票
0 回答
127 浏览

javascript - Angular Cookie 重置

我正在使用 Angular + REST Api 创建汽车搜索模块。

我已经阅读了这里的大部分文章,其中没有一篇有我遇到的问题;

Angular Cookies 在 localhost 上运行良好,当我将其上传到服务器时,它无法正常工作。

在提货页面上,用户选择的字段很少,这些信息存储在 cookie 中,因为它点击搜索按钮导航到搜索页面并尝试从 cookie 获取信息,但无法获取用户存储的信息,我正在获取默认值。

我创建了小型服务代码片段。

0 投票
3 回答
2795 浏览

angularjs - ngCookies returns undefined for existing cookie

I've been scratching my head for this one for hours now yet still haven't found the cause or solution.

Basically I have an Angular.js frontend that tries to log users in (with ngCookies on Angular.js 1.3.15) by communicating with an authentication API endpoint in the backend. Upon success, my code should redirect the user to another page.

So the login code looks something like:

where auth is a service that has a login method which simply sends an POST request to the backend. $state.go('overview') will do the redirect. This code should be ok as I get HTTP200 back from the server given I supply the correct user credentials. However, the browser won't redirect me to the overview page because it still thinks I'm not logged in unless I refresh the page.

The code that checks if the current user is logged in uses a helper method called getToken(), where I use ngCookies to retrieve a cookie named USER_SESSION. And this method is where I think the problem is.

The method itself is simply

However it always returns undefined even when the USER_SESSION cookie exists in the browser.

Some testing I did (on a remote testing server so accessing cookies in localhost shouldn't be a concern):

The results of console.log:

Are the double quotes the problem here? I thought so initially, but after refreshing the page, $cookies returns the same thing (same double quotes but a different USER_SESSION value) and $cookies.USER_SESSION would have the correct value, and user would be on the overview page.

Does this mean Set-Cookie in the HTTP response header needs a page refresh to take effect?

Thanks!

P.S. Same problem occurs with cookieStore.