phenomnomnominal / angular-2-local-storage Goto Github PK
View Code? Open in Web Editor NEWLocalStorageService for Angular 2 with the same API as angular-local-storage
License: MIT License
LocalStorageService for Angular 2 with the same API as angular-local-storage
License: MIT License
Is it possible to add more use cases?
In your index.js you have
//# sourceMappingURL=../../dist/index.js.map
This is wrong. After install, there is no dist folder
All you need is ./index.js.map
This also apply to all other js files created.
would it be possible to define domain?
in an angular1x packet, there is a possibility, but I have not found anything 2x +.
Issue was related to: #30
I'm getting this error when running ng test
Error: StaticInjectorError(DynamicTestModule)[AuthenticationService -> LocalStorageService]:
error properties: Object({ ngTempTokenPath: null, ngTokenPath: [ 'AuthenticationService', Function ] })
at <Jasmine>
at NullInjector.push../node_modules/@angular/core/fesm5/core.js.NullInjector.get node_modules/@angular/core/fesm5/core.js:979:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1232:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1182:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1077:1)
at resolveToken node_modules/@angular/core/fesm5/core.js:1232:1)
at tryResolveToken node_modules/@angular/core/fesm5/core.js:1182:1)
at StaticInjector.push../node_modules/@angular/core/fesm5/core.js.StaticInjector.get node_modules/@angular/core/fesm5/core.js:1077:1)
at resolveNgModuleDep node_modules/@angular/core/fesm5/core.js:9238:1)
at _createClass node_modules/@angular/core/fesm5/core.js:9277:1)
3rd party libraries may access localStorage through window object which saves strings (e.g. authentication tokens by angular2-jwt) without quotes, e.g. (abcd...)
as the result - there is no way to access saved data.
Hi,
How to store a value from an input text and then retrieve it in the component ?
ex : <input type="text" [(ngModel)]="number">
And in my component do something like this : @LocalStorageService() public number:number
It will be nice to put a complete example
While I'm running compile, TSC shows the following error. It seems, that in my txjs there's no 'rx' file, only 'Rx'.
While it appears to be working correctly, the version compatibility should be updated.
Hi,
I had to add
map {
...,
'angular-2-local-storage': 'npm:angular-2-local-storage/dist'
},
and
packages: {
...,
'angular-2-local-storage': { main: './angular-2-local-storage.js', defaultExtension: 'js' }
}
to get angular-2-local-storage work as documented.
Otherwise I got 404 for /angular-2-local-storage requests.
Using v0.0.20 from via npm install
.
I'm relatively new to all this npm and SystmJS stuff (been living in a cave for about five years now) so I just wanted to know if this is a "it's not a bug, it's a feature" case.
This error occurred after installing the latest version of angular-2-local-storage. Possibly a bug?
import { Component } from '@angular/core';
import { Platform, ionicBootstrap } from 'ionic-angular';
import { StatusBar } from 'ionic-native';
import { LocalStorageService, LOCAL_STORAGE_SERVICE_CONFIG } from 'angular-2-local-storage';
// Create config options (see ILocalStorageServiceConfigOptions) for deets:
let localStorageServiceConfig = {
prefix: 'my-app',
storageType: 'sessionStorage'
};
// Provide the config to the service:
const LOCAL_STORAGE_CONFIG_PROVIDER: Provider = provide(LOCAL_STORAGE_SERVICE_CONFIG, {
useValue: localStorageServiceConfig
});
// Use the provider:
ionicBootstrap(MyApp, [LocalStorageService, LOCAL_STORAGE_CONFIG_PROVIDER]);
TypeScript error: app/app.ts(29,38): Error TS2304: Cannot find name 'Provider'.
TypeScript error: app/app.ts(29,49): Error TS2304: Cannot find name 'provide'.
Is it possibile to change from sessionStorage to localStorage dynamically, for example into a service?
Is it exist a method like "setStorageType"?
It only includes v2.0.0.
When running ng build -prod I am getting this exception using the latest version of the angular-2-local-storage.
If I install the previous version 1.0.1 I don't have any issues?
Hi, I read you use most of the code from angular-local-storage, but this method clearAll
there has an optional parameter, the regex.
On angular-2-local-storage I'm obliged to inform the regex. My question is, if I do something like this this.localStorageService.clearAll('');
will it work the same way or you validate/require a regex for removal? If that's the case, do you plan on implementing that functionality?
Thanks!
Getting this error as a conflict between the es6 shim and core-js.
\node_modules@types\core-js\index.d.ts(21,14): error TS2300: Build:Duplicate identifier 'PropertyKey'.
\wwwroot\modules\angular-2-local-storage\typings\globals\es6-shim\index.d.ts(3,14): error TS2300: Build:Duplicate identifier 'PropertyKey'.
I've tried putting all manner of things in my ts.config exclude section but can't seem to get past this. Any ideas? Should the shim really be in there anyway?
I have a case when I need to create service with help of Injector
.
this.injector.get(LocalStorageService);
Now, I get exception.
zone.js:643 Unhandled Promise rejection: Cannot read property 'notifyOptions' of undefined ; Zone: ; Task: Promise.then ; Value: TypeError: Cannot read property 'notifyOptions' of undefined
at new LocalStorageService (local-storage.service.js:34)
@phenomnomnominal Could you check please. I don't want to switch to another local storage service
I need to Expire value added to the Local storage after 60 minutes is there any way we can achieve it using this package
I'm getting this error after i update to angular 5: ERROR TypeError: (intermediate value).share is not a function at new LocalStorageService (local-storage.service.js:45)
The error is at this line: this.errors$ = new Observable_1.Observable(function (observer) { return _this.errors = observer; }).share();
Anyone have any idea why it is happening?
a
When running ng serve I am getting this exception using the 1.0.1version of the angular-2-local-storage.
I really don't want to configure anything when using local storage. It would be great if we could make the LOCAL_STORAGE_SERVICE_CONFIG provider optional
I see there's a 3.0.1 release available via npm, and it's red-flagged as a major release with potentially breaking changes, but I can't find any release notes to know what's in this release, what may break (if anything), and where the test points are.
Am I looking in the wrong place, or are there release notes still coming?
Thanks!
Facing the following error while deploying as Angular 10 has deprecated the use of ModuleWithProviders type without a generic and the code in dist folder remains unchanged in the deployment causing the build to fail.
2021-01-18T14:33:33.8414506Z ERROR in node_modules/angular-2-local-storage/dist/local-storage.module.d.ts:4:65 - error TS2314: Generic type 'ModuleWithProviders' requires 1 type argument(s).
2021-01-18T14:33:33.8414883Z
2021-01-18T14:33:33.8415138Z 4 static withConfig(userConfig?: ILocalStorageServiceConfig): ModuleWithProviders;
It included *.d.ts files which is great. But it also included *.ts files.
The result is if I try to use typescript to build my project into ES6/ES2015, I got errors like this:
error TS6059: File '/Users/gordon/workspace/CraigsMenu/web/node_modules/angular-2-local-storage/src/ILocalStorageEvent.ts' is not under 'rootDir' '/Users/gordon/workspace/CraigsMenu/web/app'. 'rootDir' is expected to contain all source files.
error TS6059: File '/Users/gordon/workspace/CraigsMenu/web/node_modules/angular-2-local-storage/src/ILocalStorageServiceConfig.ts' is not under 'rootDir' '/Users/gordon/workspace/CraigsMenu/web/app'. 'rootDir' is expected to contain all source files.
error TS6059: File '/Users/gordon/workspace/CraigsMenu/web/node_modules/angular-2-local-storage/src/INotifyOptions.ts' is not under 'rootDir' '/Users/gordon/workspace/CraigsMenu/web/app'. 'rootDir' is expected to contain all source files.
error TS6059: File '/Users/gordon/workspace/CraigsMenu/web/node_modules/angular-2-local-storage/src/LocalStorageService.ts' is not under 'rootDir' '/Users/gordon/workspace/CraigsMenu/web/app'. 'rootDir' is expected to contain all source files.
error TS6059: File '/Users/gordon/workspace/CraigsMenu/web/node_modules/angular-2-local-storage/src/LocalStorageServiceConfig.ts' is not under 'rootDir' '/Users/gordon/workspace/CraigsMenu/web/app'. 'rootDir' is expected to contain all source files.
My tsconfig.json file looks like this:
{
"compilerOptions": {
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"declaration": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"outDir": "./dist",
"rootDir": "./app"
},
"compileOnSave": false,
"files": [
"app/main.ts"
]
}
The build command is simply: tsc -p tsconfig.json
If I use that method, then JSON.stringify(user);
return {}
I had problem and i spent more time to resolve that issue:
Solution:
SYSTEM_CONFIG_DEV: any = {
defaultJSExtensions: true,
packageConfigPaths: [
...
],
paths: {
....
'angular-2-local-storage': 'node_modules/angular-2-local-storage/dist/index.js',
...
},
packages: {
'angular-2-local-storage': {
main: 'index.js',
defaultExtension: 'js'
}
}
};
Here still the Angular 6+ Support is not published to npm
I am having an issue creating/running a unit test using angular-2-local-storage. I believe I have the test setup correctly, but getting this error. Not sure what to do next.
Error: No provider for LOCAL_STORAGE_SERVICE_CONFIG!
Setting up the test:
import { LocalStorageModule, LocalStorageService } from 'angular-2-local-storage';
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
LocalStorageModule.withConfig({
prefix: 'bpf',
// storageType: 'localStorage'
storageType: 'sessionStorage'
})
],
declarations: [
DisabilityQuoteComponent
],
providers: [LocalStorageService,
{ provide: WorkInProgressService, useValue: MockWorkInProgressService
}
]
})
.compileComponents();
}));
this.localStorage.setItems$.subscribe(
()=>this.router.navigate(["/dashboard"])
);
This module is working fine in chrome, safari of desktop. but I tested my application in iphone safari , localstorage values are not retrieved. any solution for this?
zone.js:484 Unhandled Promise rejection: (SystemJS) XHR error (404 Not Found) loading http://localhost:4200/vendor/angular-2-local-storage/index.js
When ng build is done the dist/vendor/angular-2-local-storage indside not have index.js file.
I am used your document. my system-config.ts file is
const map: any = {
'angular-2-local-storage': 'vendor/angular-2-local-storage',
};
const packages: any = {
'angular-2-local-storage': { main: 'index.js', defaultExtension: 'js' },
}
const barrels: string[] = [
// Thirdparty barrels.
'rxjs',
'angular-2-local-storage',
]
Please help.
angular 2 local storage updated on angular 2.0 version? How to config this one?
The referenced library was released under an MIT license, but this repo doesn't include a license file.
Is this also MIT, and can you include a license file in the repo?
Thanks!
I am trying to get the local storage to persist some auth token info, and it is occurring in a service.
Strangly enough it does not seem to want to persist. If I redirect to the auth middleware (IdentityServer3) and then redirect back to the original site, the data I persisted is not there anymore. Is there something special I need to do to get localstorage to work for a service?
im using lib in my project
Angular CLI: 6.0.0-rc.2
Node: 8.11.1
OS: win32 x64
Angular: 6.0.0-rc.3
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router
@angular/cdk: 6.0.0-rc.1
@angular/cli: 6.0.0-rc.2
@angular/material: 6.0.0-rc.1
@angular-devkit/architect: 0.5.4
@angular-devkit/build-angular: 0.5.4
@angular-devkit/build-optimizer: 0.5.4
@angular-devkit/core: 0.5.4
@angular-devkit/schematics: 0.5.4
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 6.0.0-rc.2.4
@schematics/angular: 0.5.4
@schematics/update: 0.5.4
typescript: 2.7.2
webpack: 4.5.0
it was working on 1.7.4 with 5.x rxjs
today i tried to update to cli rc2 and rxjs rx1 and got this
ERROR in ./node_modules/angular-2-local-storage/dist/local-storage.service.js
Module not found: Error: Can't resolve 'rxjs/Observable' in 'C:...node_modules\angular-2-local-storage\dist'
ERROR in ./node_modules/angular-2-local-storage/dist/local-storage.service.js
Module not found: Error: Can't resolve 'rxjs/Subscriber' in 'C:...node_modules\angular-2-local-storage\dist'
ERROR in ./node_modules/angular-2-local-storage/dist/local-storage.service.js
Module not found: Error: Can't resolve 'rxjs/add/operator/share' in 'C:...node_modules\angular-2-local-storage\dist'
can you maybe update new rxjs syntax using pipe() thanks
The https://github.com/grevory/angular-local-storage#cookie have
localStorageService.cookie.set(key,val,10)
as example, but cookie doesn't exists in #angular-2-local-storage, at least not at this way.
Hi there,
I have noticed this application storing all values with double quotes in IE regardless of the type of the variable unlike chrome, where the values are saved as its type. This is creating issue for me to share the value with other sub-domain applications.
Even though session storage keys are same, angular-2-local-storage returning null for values set by other application.
Chrome output
Any helps appreciated!
Thanks in advance,
Sadik
Hello , we are currently facing this problem when trying to ng build --prod ,
any solution for this?
ERROR in node_modules/angular-2-local-storage/local-storage.module.d.ts:4:62 - error TS2314: Generic type 'ModuleWithProviders<T>' requires 1 type argument(s).
4 static forRoot(userConfig?: ILocalStorageServiceConfig): ModuleWithProviders;
Considering myself as a noob and couldnt figure out how to use setItem and getItem.
I am getting error at this point.
this.localStorage.setItems$.subscribe("cities", "Hello world");
We should do this.
Promise fails.
zone.js:101 GET http://localhost:4200/angular-2-local-storage 404 (Not Found)
Any idea why this is happening? I'm using the angular cli
I added the npm and did the config as your documentation suggested. The module is found in the editor, I just get the error in the browser console when I run the app (ng serve).
Thanks
UPDATE:
It worked after I edited the system-config.ts
I'm not sure if this is a problem with my code or this repository but I tried to use it with angular 4 and it failed (don't have the error message right now, can try it again if needed).
Are you aware of any limitations that will prevent this code from running with angular 4?
I'm setting a local storage variable by toggling a button. The subscribe is working as expected in the component it's being triggered from, but fires only the first time in the directive, subsequent changes are not picked up.
I feel like this might be an Angular thing, or how I've architected it, but just wondering if subscribing in directives is a known issue.
Thanx for this great plugin!
I have a question. I am using angular 4.3.5 with angular cli 1.3.2 and compile my code with aot enabled.
How can i use a variable stored in global window-variable for prefix?
import { LocalStorageModule } from 'angular-2-local-storage';
// window.ownVariables.var1 is initialized in index.html !
const myVariable = `my-app-${window.ownVariables.var1}`;
@NgModule({
imports: [
LocalStorageModule.withConfig({
prefix: `my-app-${myVariable}`,
storageType: 'localStorage'
})
],
declarations: [
..
],
providers: [
..
],
bootstrap: [AppComponent]
})
export class AppModule {}
The variable myVaraible is undefined at compile time of aot. Do you have any ideas to solve this problem? Is there a possibility to set the prefix in another way?
get _LocalStorageService_75():import44.LocalStorageService { if ((this.__LocalStorageService_75 == (null as any))) { (this.__LocalStorageService_75 = new import44.LocalStorageService()); } return this.__LocalStorageService_75; }
ngc : Error : [ts] Supplied parameters do not match any signature of call target.
constructor LocalStorageService(config: ILocalStorageServiceConfig): import44.LocalStorageService
Firefox: 49.0
After localStorage gets disabled in Firefox (about:config > dom.storage.enabled set to false)
Exception occurs:
ORIGINAL EXCEPTION: TypeError: this.warnings is undefined ORIGINAL STACKTRACE: LocalStorageService.prototype.get@http://localhost:5000/build/webdeps/angular-2-local-storage/LocalStorageService.js:85:13
I'm guessing it's written when angular2 was in beta?
The provider and bootstrap stuff does not match angular2 rc pattern
https://github.com/phenomnomnominal/angular-2-local-storage#in-your-app
Hi,
I update to 3.0.0
and the project runs perfectly to serve development.
But when I generated the build, the project don't run and I get the follows error on console:
main.42b2efa0809ff1ad1245.js:1 TypeError: Cannot read property '__source' of undefined
at t.get (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at lg (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at t.get (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at De (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at Pe (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at Re (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at vendor.3ff8dc4fe5013ffbc0c4.js:1
at vendor.3ff8dc4fe5013ffbc0c4.js:1
at hg (vendor.3ff8dc4fe5013ffbc0c4.js:1)
at lg (vendor.3ff8dc4fe5013ffbc0c4.js:1)
For now I needed to install the 2.0.0
again.
I use Angular 7.2.0
.
Thanks!
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.