ngx-store
ngx-store copied to clipboard
Setting to empty string, then to a non-empty string does not work
This is my service:
@CookieStorage({key: 'iso-language'}) private _isoLanguage: string;
public getIsoLanguage() {
return this._isoLanguage;
}
public setIsoLanguage(language: string) {
this._isoLanguage = language;
}
When I run setIsoLanguage('test') it works fine, getIsoLanguage() returns 'test' However, when I run setIsoLanguage('') and then setIsoLanguage('test2'), getIsoLanguage() will still return the empty string.
Enabled debugging, but nothing obvious, it does show it's updating it.
When I set it to null instead of '' it works fine.
@roldengarm You need to set a default value for the variable.
@CookieStorage({key: 'iso-language'}) private _isoLanguage: string = null;
Not sure if it will fix your problem, but not setting it caused various unexpected errors for me.
Yep, remember the default value on the property. I had some very weird issues when i forgot that as well.