Closed brendanalexdr closed 7 years ago
Same here on Angular 2.4.1. It works when not passing options as the 3rd argument of .put()
.
This line causes the error.
@nukuuk I think this is related to https://github.com/salemdar/angular2-cookie/issues/37. I think the culprit here is my temporary fix. Since we provided a blank object for the CookieOptions
. It throws the error about .merge()
is not a function and the class CookieOptions
defines the .merge()
function.
What do you think of this @salemdar ?
@exequiel09 I am using the fix as mentioned in #37 thread:
{ provide: CookieOptions, useValue: {} }
But still get this 'newOpts.merge is not a function' error. However, seems the culprit certainly is CookieOptions.
@nukuuk Checkout the new solution on #37 but that will only work on JIT not on AOT.
All solution Doesn't work for me. when i don't add options it work. when i add options it doesn't work. i don't use AOT.
have tried :
{ provide: CookieOptions, useValue: {} }
and :
import { BaseCookieOptions, CookieService, CookieOptions } from 'angular2-cookie/core';
{ provide: CookieOptions, useClass: BaseCookieOptions }
Nothing work.
@Spawnrad
Works fine for me, with Angular 2.4.8, BUT without a 3rd parameter for the .put
method (so, this means not being able to set an expiration date):
In app.module.ts
:
import { CookieService, CookieOptions } from 'angular2-cookie/core';
// ...
providers: [
// ...
CookieService,
{ provide: CookieOptions, useValue: {} }
]
And simply inject CookieService
in whatever component/service you want to use it, of course.
@MrCroft Could I ask if there is another way to include expiration dates? Many thanks!
@SyangC Sorry, haven't figured out any, yet... Luckily for me, don't really need it now.
Damn. Thanks anyways!
@MrCroft @SyangC @Spawnrad
I find a way.
use
{ provide: CookieOptions, useValue: false }
because in angular2-cookie source code
var defaultOpts = this._defaultOptions || new base_cookie_options_1.CookieOptions({ path: cookiePath }); var opts = this._mergeOptions(defaultOpts, options);
so if this._defaultOptions is false.
defaultOpts is the correct type
Please use the new library guys:
I get the same with the other library also when using AOT.
the new library introduced a new error and is not working with angular 5
I'm using angular2-cookie v1.2.6. I am now getting the following error (was working in previous versions):
Here is the code:
`saveToken(token: string, loginEmail: string) { let dtm = new Date(); let minutes = 115; dtm.setTime(dtm.getTime() + (minutes 60 1000)); this.cookieService.put('tokenCookie', token, { expires: dtm, path: '/' });
Is there something wrong with my code? Or is this a bug? Thank for any help on this.