Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
angular2-localstorage
Advanced tools
Angular2 decorator to save and restore class properties automatically from LocalStorage.
This little Angular2/typescript decorator makes it super easy to save and restore automatically a variable state in your directive (class property) using HTML5' LocalStorage.
npm install angular2-localstorage
var appPromise = bootstrap(MyRootAppComponent);
// register LocalStorage, this registers our change-detection.
import {LocalStorageSubscriber} from 'angular2-localstorage/LocalStorageEmitter';
LocalStorageSubscriber(appPromise);
LocalStorage
decoratorimport {LocalStorage} from "angular2-localstorage/LocalStorage";
class MySuperComponent {
@LocalStorage() public lastSearchQuery:Object = {};
@LocalStorage('differentLocalStorageKey') public lastSearchQuery:Object = {};
}
Note: Define always a default value at the property you are using @LocalStorage
.
Note: The localStorage key is per default the property name. Define the first argument of @LocalStorage
to set different one.
Note: Please don't store circular structures as this library uses JSON.stringify to encode before using LocalStorage.
@Component({
selector: 'app-login',
template: `
<form>
<div>
<input type="text" [(ngModel)]="username" placeholder="Username" />
<input type="password" [(ngModel)]="password" placeholder="Password" />
</div>
<input type="checkbox" [(ngModel)]="rememberMe" /> Keep me logged in
<button type="submit>Login</button
</form>
`
})
class AppLoginComponent {
//here happens the magic. `username` is always restored from the localStorage when you reload the site
@LocalStorage() public username:string = '';
public password:string;
//here happens the magic. `rememberMe` is always restored from the localStorage when you reload the site
@LocalStorage() public rememberMe:boolean = false;
}
@Component({
selector: 'admin-menu',
template: `
<div *ngFor="#menuItem of menuItems() | mapToIterable; #i = index">
<h2 (click)="hiddenMenuItems[i] = !!!hiddenMenuItems[i]">
{{i}}: {{category.label}}
</h2>
<div style="padding-left: 15px;" [hidden]="hiddenMenuItems[i]">
<a href>Some sub menu item 1</a>
<a href>Some sub menu item 2</a>
<a href>Some sub menu item 3</a>
</div>
</div>
`
})
class AdminMenuComponent {
public menuItems = [{title: 'Menu1'}, {title: 'Menu2'}, {title: 'Menu3'}];
//here happens the magic. `hiddenMenuItems` is always restored from the localStorage when you reload the site
@LocalStorage() public hiddenMenuItems:Array<boolean> = [];
}
FAQs
Angular2 decorator to save and restore class properties automatically from LocalStorage.
The npm package angular2-localstorage receives a total of 28 weekly downloads. As such, angular2-localstorage popularity was classified as not popular.
We found that angular2-localstorage demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.