From this repo, I've successfully configured this:
import {Component} from "angular2/core";
import {LocalStorageService} from "angular2-localstorage/LocalStorageEmitter";
@Component({
provider: [LocalStorageService]
})
export class AppRoot{
constructor(private storageService: LocalStorageService){}
...
}
How can I use storageService to set or get in local storage? I can't find example anywhere even in the doc.
After some testing, I've managed it to get it working with Decorator through WebStorage:
import {LocalStorage, SessionStorage} from "angular2-localstorage/WebStorage";
@Component({})
export class LoginComponent implements OnInit {
@LocalStorage() public username:string = 'hello world';
ngOnInit() {
console.log('username', this.username);
// it prints username hello world
}
}
However, when I used Chrome Dev to see my localstorage, I see nothing there:
And In another component,
import {LocalStorage, SessionStorage} from "angular2-localstorage/WebStorage";
@Component({})
export class DashboardComponent implements OnInit {
@LocalStorage() public username:string;
ngOnInit() {
console.log(this.username);
// it prints null
}
}
A good set is a ball delivered in between the antennas, and with one or two feet off the net. For both setters when a ball is in front of the hitter that gives a lead-up position that facilitates the hitter's approach. Learning how to set takes lots of time and practice.
Setting is the second step of passing, and it can be done to either dump the ball over into an undefended spot or to “set” the ball into a position that allows the hitter to spike it over. The perfect set is a high ball, just inches from the net.
I would prefer to create a separate Injectable service
import { Injectable } from '@angular/core';
@Injectable()
export class LocalStorageService {
constructor() {
//
}
public setData(key:string, data:any) {
localStorage.setItem(key, JSON.stringify(data));
}
public getData(key:string) {
return JSON.parse(localStorage.getItem(key));
}
public removeData(key:string) {
localStorage.removeItem(key);
}
}
And in your component
import { LocalStorageService } from './../../services/localStorageService';
@Component({
selector: 'member-claims-modal',
templateUrl: './view.html'
})
export class UserComponent {
constructor(private localStorageService:LocalStorageService) {
super();
}
public SampleMethod() {
let cloneData = {
'claims': 'hello'
};
this.localStorageService.setData('claims', cloneData);
let item=this.localStorageService.getData('claims');
consoloe.log(item);
this.localStorageService.removeData('claims');
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With