如何在Angular 2 app中使用angular2-local-storage模块

slo*_*own 13 angular

如何在Angular 2中使用此模块?任何例子?

到目前为止,我安装了模块并导入了Angular 2组件.

https://www.npmjs.com/package/angular2-local-storage

Gün*_*uer 8

导入并添加到 bootstrap()

bootstrap(AppComponent, [OtherProvider, LocalStorage]);
Run Code Online (Sandbox Code Playgroud)

将其注入要使用它的组件,指令或服务中.

export class SomeComponent {
  constructor(private ls:LocalStorage) {}
  clickHandler() {
    this.ls.set('someKey', 'someValue');
  }
  otherClickHandler() {
    console.log(this.ls.get('someKey'); // should print 'someValue'
  }
}
Run Code Online (Sandbox Code Playgroud)