ngx-store icon indicating copy to clipboard operation
ngx-store copied to clipboard

Setting to empty string, then to a non-empty string does not work

Open roldengarm opened this issue 6 years ago • 2 comments

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 avatar Aug 20 '18 21:08 roldengarm

@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.

MarkoSulamagi avatar Aug 21 '18 03:08 MarkoSulamagi

Yep, remember the default value on the property. I had some very weird issues when i forgot that as well.

Moulde avatar Sep 18 '18 20:09 Moulde