For saving values while refreshing the page, you can use the localStorage
or the sessionStorage
for that. There is no external library or import necessary. It should work out of the box in most of the browsers.
For saving:
// clicks is the variable containing your value to save localStorage.setItem('clickCounter', clicks); // If you want to use the sessionStorage // sessionStorage.setItem('clickCounter', clicks);
For loading:
const clicks = localStorage.getItem('clickCounter'); // If you want to use the sessionStorage // const clicks = sessionStorage.getItem('clickCounter');
You can check this in Chrome using the dev tools.
Related Posts:
- Difference between Constructor and ngOnInit
- Can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’
- document.getElementById replacement in angular4 / typescript?
- TS1086: An accessor cannot be declared in ambient context
- Angular2 Error: There is no directive with “exportAs” set to “ngForm”
- ‘router-outlet’ is not a known element
- Error when trying to inject a service into an angular component “EXCEPTION: Can’t resolve all parameters for component”, why?
- No provider for HttpClient
- How to implement sleep function in TypeScript?
- Can’t bind to ‘routerLink’ since it isn’t a known property
- How to use bootstrap 4 in angular 2?
- Module has no exported member error in angular module
- How to apply filters to *ngFor?
- Select default option value from typescript angular 6
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- Could not find module “@angular-devkit/build-angular”
- Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’
- AngularJS vs Angular [closed]
- When to use ‘npm start’ and when to use ‘ng serve’?
- ExpressionChangedAfterItHasBeenCheckedError Explained
- Angular 10 – can’t bind to ‘formGroup’ since it isn’t a known property of ‘form’
- How to use *ngIf else?
- ngFor with index as value in attribute
- How to upgrade Angular CLI to the latest version
- What is pipe for in RxJS?
- Angular: Get current index in ngFor
- What is .subscribe in Angular?
- BehaviorSubject vs Observable?
- Angular 6 “Can’t bind to ‘ngModel’ since it isn’t a known property of ‘input’.”
- Failed to load resource: net::ERR_CONNECTION_REFUSED : Nodejs
- Angular: mat-form-field must contain a MatFormFieldControl
- (change) vs (ngModelChange) in angular
- What is the difference between Promises and Observables?
- mat-form-field must contain a MatFormFieldControl
- Angular File Upload
- formSelect() method in materialize does’nt work in angular 6 inputs
- ERROR Error: No value accessor for form control with unspecified name attribute on switch
- form control error:ERROR Error: No value accessor for form control with unspecified name attribute
- You seem to not be depending on “@angular/core” and/or “rxjs”. This is an error
- Unable to resolve dependency tree error when installing npm packages
- Angular ForEach in Angular4/Typescript?
- ‘ng’ is not recognized as an internal or external command, operable program or batch file
- Kendo Angular Chart change legend position based on size
- Angular4 – No value accessor for form control
- Why do i need `typings.json` file in an Angular 2 project?
- node_modules/rxjs/internal/types.d.ts(81,44): error TS1005: ‘;’ expected error after installation of Angular 6
- TypeScript-‘s Angular Framework Error – “There is no directive with exportAs set to ngForm”
- Unexpected value ‘undefined’ declared by the module ‘AppModule’
- I get “Http failure response for (unknown url): 0 Unknown Error” instead of actual error message in Angular
- Where to place/find the systemjs.config.js file in an angularJS2 project?
- ng serve does not work
- What is the equivalent of ngShow and ngHide in Angular 2+?
- npm WARN … requires a peer of … but none is installed. You must install peer dependencies yourself
- how to refresh page in angular 2
- What is ViewChild in Angular2?
- Repository is not clean. Please commit or stash any changes before updating In Angular 8
- Repository is not clean. Please commit or stash any changes before updating In Angular 8
- Property ‘map’ does not exist on type ‘Observable
‘ - Angular 2 Cannot read property ‘config’ of null
- Set focus on element
- Cleanest way to reset forms
- Angular2 CLI error “@angular/compiler-cli” package was not properly installed
- Angular2 – How to create a simple table
- Angular material Could not find Angular Material core theme
- Angular EXCEPTION: No provider for Http
- Error : Cannot find primary outlet to load
- cannot find module ‘@angular/http’?
- Templating with href in angular (4)
- Angular 2 : No NgModule metadata found
- Angular 2 Checkbox Two Way Data Binding
- File Upload In Angular?
- is there any alternative for ng-disabled in angular2?
- Angular 2.0 and Modal Dialog
- Cannot find module ‘@angular/compiler’
- Angular 2 [hidden] does not seem to be working?
- Local workspace file (‘angular.json’) could not be found. But same code works in another computer
- You have to be inside an angular-cli project in order to use the serve command
- Angular 4 setTimeout() with variable delay and wait
- How to get current route
- Angular4 core.es5.js Uncaught reflect-metadata shim is required when using class decorators
- Angular error: Please add a @NgModule annotation
- How to enable production mode?
- Angular 5: “No provider for ControlContainer”
- Getting No provider for NgControl Error after adding ReactiveFormsModule to my angular 4 app
- How to use `trackBy` with `ngFor`
- Why do i need `typings.json` file in an Angular 2 project?
- Angular routerLink does not navigate to the corresponding component
- How to use jQuery with Angular?
- Mask for an Input to allow phone numbers?
- How do I download a file with Angular2 or greater
- What is the best way to delete a component with CLI
- Angular2 – Http POST request parameters
- Angular 2 Sort table columns
- GET http://localhost:4200/null 404 (Not Found) in angular2 with angular-cli
- Angular design pattern: MVC, MVVM or MV*?
- How do I install Angular 2 using NPM?
- Check if Variable is Empty – Angular 2
- Angular 2 multiple modules
- Electron – Not allowed to load local resource
- angular-cli where is webpack.config.js file – new angular6 does not support ng eject