Can't delete cookie with AngularJS's $cookies

前端 未结 3 1630
遇见更好的自我
遇见更好的自我 2021-01-17 09:28

My web app is made so that when a user logs in the server adds a Set-Cookie header to the response, like this:

Set-Cookie:JSESSIONID=1; Path=/myApp/; Secure

3条回答
  •  长发绾君心
    2021-01-17 09:53

    I suppose you should check the responses from server - maybe they include a 'set cookie' header field that sets the cookie's value.

    Here is a Plunker example that illustrates how you can add/change/delete/watch for cookie's value (but without server-side responses that can change cookie values).

    But generally, $cookies object is kind of 'proxy object' that is two-way tracked by AngularJS ngCookies module and from one side change its fields when browser's cookies are changed (so you can $watch for changes) but also changes are reflected to browser's real cookies, so you can change this object.

    So the only reason why cookies cannot be deleted is that you delete them on browser, and server sets the cookie again and after reloading page it is still there.

提交回复
热议问题