ivpusic / angular-cookie Goto Github PK
View Code? Open in Web Editor NEWLightweight Angular module for access to cookies
License: MIT License
Lightweight Angular module for access to cookies
License: MIT License
I thought return false, when no cookies were found was better than returning an emptyobject.
I used jquery to check if it was empty though :/
if ($.isEmptyObject(cookies)){
return false;
}else {
return cookies;
}
The following value of a cookie is throwing error:
%7B%22mediaUrl%22%3A%22http%3A//ireland1.cutvmanifest.api.ottcloudservices.com/smooth/M1_SS/1407418200-1407421680/manifest%22%2C%22laUrl%22%3A%22http%3A//license.totalmovie.com/playready/rightsmanager.asmx%22%2C%22programId%22%3A%22LSC_SAN_19_10497509%22%2C%22programName%22%3A%22Az%20%E9let%20megy%20tov%E1bb%22%2C%22channelId%22%3A%22LCH_SAN_19_2%22%2C%22channelName%22%3A%22M1%22%2C%22mode%22%3A%22normal%22%2C%22castAvailable%22%3Atrue%2C%22chromecast%22%3A%22%22%2C%22castingDevice%22%3A%22%22%2C%22playing%22%3Atrue%7D
The line is:
value = decodeURIComponent(cookie.substring(pos + 1));
I haven't had the opportunity to test or troubleshoot throughly, but using Firefox, we're not able to properly remove the cookie using
$cookie.remove(key, { path: '/some/path' });
Just doesn't work. Any insights?
If you can try and remove the jquery dependancy.
Have a look at:
http://bob.yexley.net/creating-and-maintaining-your-own-bower-package/#updatingandmaintenance
and
http://bob.yexley.net/creating-and-maintaining-your-own-bower-package/#githubreleases
This package doesn't have any version information because the repository doesn't have any tags.
This means that when you run bower install -S angular-cookie
the configuration file will look like:
{
"name": "...",
"version": "...",
"dependencies": {
"angular-cookie": "*"
}
}
because bower info angular-cookie
returns No versions available
.
I am gettings this
[$injector:nomod] Module 'ngLocale' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. http://errors.angularjs.org/1.2.7/$injector/nomod?p0=ngLocale
Firefox is not adding cookies.
Not receive any error, it just does not set.
It's all right as the privacies.
ipCookie ('globals', $rootScope.globals, {path: '/', expires: 0.1});
if i set
ipCookie('credentials', usercookie , { expires: 1, expirationUnit: 'minutes' });
chrome cancel the cookie after 1 minute, firefox no.
Hi,
Could you please upgrade dependencies of your module (specifically bower, but not only). Old versions have known high severity vulnerabilities and may cause problems.
Hi,
I'm using angular-cookie in a new application to control popup campaigns across multiple sites.
However it seems if we leave domain and path unset, then the module will automatically insert both the domain and also the path.
So if I wanna do a wildcard on path, like /* in terms of the cookie being set generally for the entire domain, and not just a specific page, would this be the correct way to implement this feature?
Thanks for taking your time to build and maintain this awesome module!
There is a provider version for this module? I need to check the existence of a cookie inside the .config()
in my application.
Hello, you have probably "bug" in README
In this usage example
ipCookie(key, value, { expire: 21 });
should be expires, I think.
Best regards
JB
In the official angular js $cookies
module, you can use the cookies on the ng-model
, as its is POJ.
Something like this
$scope.cookies = $cookies;
<td>
<label class="radio-inline">
<input type="radio" data-ng-model="cookies.animations" data-ng-change="setAnimateClass(true);" value="true"> <span data-translate="FORM.ON">On</span>
</label>
<label class="radio-inline">
<input type="radio" data-ng-model="cookies.animations" data-ng-change="setAnimateClass(false);" value="false"> <span data-translate="FORM.OFF">Off</span>
</label>
</td>
What is the best way to do this with angular-cookie
?
When I use the {secure:true} option some of the key:values are not stored.
I have 3 different keys, the 3 are saved properly when I don't use the secure option, but only (the shortest) 2 are saved when I use the secure option.
The structure of the object value that is not saved looks something like this:
{
attr_a: {
attr_a_1: someValue_1,
attr_a_2: someValue_2,
attr_a_3: someValue_3,
attr_a_4: someValue_4,
},
attr_b: [
{
attr_b_1: someValue_1,
attr_b_2: someValue_2,
attr_b_3: someValue_3,
attr_b_4: someValue_4,
attr_b_5: someValue_5,
attr_b_6: someValue_6,
attr_b_7: someValue_7,
attr_b_8: someValue_8,
attr_b_9: someValue_9,
},
{
attr_b_1: someValue_1,
attr_b_2: someValue_2,
attr_b_3: someValue_3,
attr_b_4: someValue_4,
attr_b_5: someValue_5,
attr_b_6: someValue_6,
attr_b_7: someValue_7,
attr_b_8: someValue_8,
attr_b_9: someValue_9
},
{
...
}
]
}
I have experienced strange behaviour on some browsers. The library suddenly stopped working with type error URIError: malformed URI sequence
Stack trace:
cookieFun@............./angular-cookie.js:77:1
The problem comes with wrong assumption that all cookies for that domain is created only by this library and are encoded with encodeURIComponent. In some cases there are some other cookies for the domain created by another scripts which is not encoded on the same way.
The problem could be fixed by replacing:
value = decodeURIComponent(cookie.substring(pos + 1)); /* 77 row */
with:
try {
value = decodeURIComponent(cookie.substring(pos + 1));
} catch (e) {
value = cookie.substring(pos+1);
}
The whole idea to encode cookies seems to be wrong because you can accidentally damage other third party cookies for instance: google analytics cookie.
Right now, if you try and read a cookie that's a large number such as 4461381106811793314, when you fetch it using ipCookie('cookie_name') it returns it as 4461381106811793400.
Is it possible to have it not do that?
I had cookie setting constant and I used it to login and logout. But in case of logout date was overrwriten by the module. And it didn't save the cookie afterwards. I think you should use copy of cookie settings passed from user inside your module.
It'd be great if this was officially published to NPM.
Quick how to: https://gist.github.com/coolaj86/1318304
Deleting or changing a cookie by setting new values works in Chrome but not in Safari.
Any idea?
Hi there,
Thank for the solution, it works fine on every browsers else than ie 11.
I'm getting an exception line 91 in angular-cookie.js.
It's kind of sketchy to have the difference between the official repo and this one be the absence of a trailing s
.
Any thought about changing the bower module name to angular-ipCookie
or something with your personal namespace?
I set a string containing "1.0" and it treats like a number, but it should be string.
Plunker: http://plnkr.co/edit/LKDa49lsomvHGMaycWtE
I am trying to set multiple keys on a cookie with different key
values, it doesn't allow me every time I set another key and value pair it overrides my previous one(key, value).
Version number in package.json
is stuck at 1.0.0
. In the future, please update it to match the release.
Thanks!
It would be good to mention that objects can be passed as values and they're automatically serialized and deserialized.
Hey guys,
can you extend your cookies solution with ability to set the cookie HttpOnly, via config object, passed into creation of the cookie?
Example:
ipCookie('access_token', token, { expires: expireTime, expirationUnit: 'seconds', httpOnly: true });
I have 2 AngularJS applications running on my localhost. I haven't transferred it yet to a real domain.
Am I right that if I set domain on both applications to localhost, angular-cookie should be able to share the cookies to my 2 applications?
I found a bug using angular-cookies with html5mde(true);
Everything Working fine, expect $cookieStore stopped working under the functions defined in controller $scope, may be because of the .HTACCESS i didn't find any solution, now using "window.localStorage" anybody here have a solution my sample code is follow:
APLLICATION SCRIPT
// APPLICATION SCRIPT
var app = angular.module('starter', ['ngRoute','ngCookies']);
app.config(function($routeProvider, $locationProvider) {
$routeProvider
.when('/dashboard', {
templateUrl: 'pages/dashboard.html',
controller: 'dashboardApp'
})
.otherwise({
redirectTo: '/',
templateUrl: 'pages/login.html',
controller: 'loginApp'
});
$locationProvider.html5Mode(true).hashPrefix('!');
})
app.controller('loginApp', function($scope , $cookieStore ) {
//This working fine
$cookieStore.put('Greet','Welcome to Angular!');
///////////////////////////////////
$scope.doLogin = function()
{
// Here no cookie has been setting up
$cookieStore.put('loggedin', true);
};
})
.HTACCESS
#BEGIN
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^ index.html [L]
#END
cookies are saved only for session not a particular time, when set any date or time in options object ,it creates invalid date
Sorry... wrong place:)
Is there currently any way to check the expiry date of a cookie we set?
Hey man,
I am currently setting a cookie and I am expecting it to be deleted when I quit the browser and re-open, but the cookie seems to persist.
This doesn't seem like the expected behaviour as per the docs.
Is this correct? Could you tell me how it gets deleted?
Thanks!
Please, the recently published minified (angular-cookie.min.js) 4.0.4 version was not updated with the latest code:
https://github.com/ivpusic/angular-cookie/tree/v4.0.4
In the master it seems to be fixed.
I just want all website '**.mujishi.com' can user cookie and I wrote the following:
ipCookie('token', token, {expires: 20},{domain:'.mujishi.com'});
and I log in the a.mujishi.com and I can see the cookie in chrome-resources but if I open b.mujishi.com ,I can't get the cookie ,I'm wondering why?Did I write wrong or something?
This module fails with angular 1.3 and description does not contain any dependency on angular verision
When I add a specific domain (eg: domain: '.mainDomain') to my ipCookie calls, all my tests are breaking. Is there a workaround?
Hi there
I've fallen a little bit in love with Browserify recently. I find this package incredible useful (thank you) and it's a little bit irritating having to faff about pulling it in with bower.
Can you add this into npm so that I can use it with Browserify? Pretty please.
Thanks
S
So, I attempted to install angular-cookie through Bower, and after some mass confusion, I noticed this:
$ bower info angular-cookie
bower angular-cookie#* cached git://github.com/bower/bower.git#1.2.6
bower angular-cookie#* validate 1.2.6 against git://github.com/bower/bower.git#*
{
name: 'angular-cookie',
homepage: 'https://github.com/bower/bower',
version: '1.2.6'
}
Hey,
Thanks for great extension.
Module naming is incoherent. Project called angular-cookie
, which looks like it's official angular team extension. If i want to import it to angular module I need to use ivpusic.cookie
but then to use it I have to use ipCookie
, is it possible to normalize all names to something like:
ipCookie
or ivpusicCookie
?
Thanks
Hi
I can't find a way to set the HttpOnly config flag for the creation of a secure cookie.
How can I set it ? or is it actually not possible ?
Thanks for this module (far better than ngCookies...)
Not sure if this is a feature or a bug, however if I set a cookie with a specific path, .remove
does not have an effect on it, even doe' returning true
.
Navigate on a domain with a subpage like: /subpage/
ipCookie('x', 1, { path : '/subpage' });
ipCookie.remove('x') // returns true;
ipCookie('x') // returns 1, I was expecting it to be removed;
I know about the option ipCookie.remove('x', { path : '/subpage' })
however I was expecting from the return value of the remove above, to take effect on the /subpage
path as well.
This line gives error, it requires jquery I think
var all = $document.context.cookie;
#39 seems very similar to this, so I don't know if it's duplicated, if it his. Sorry about that.
So, I have encountered a problem if I set a cookie with:
ipCookie('stuff', 'helloWorld');
I cannot see it with:
$cookies
// or
$cookies.stuff
But, I can't retrieve the values with:
ipCookie
// or
ipCookie('stuff')
It's intentionally that I cannot retrieve cookies with $cookies
?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.