dscheerens / ngx-webstorage-service

Module for Angular that provides service wrappers for the Web Storage API
MIT License
65 stars 11 forks source link

My suggestion for the example code. #14

Open JanOschii opened 4 years ago

JanOschii commented 4 years ago

I needed a minute to understand the example code and I didn't think that was necessary. Therefore here is an alternative version.

import { Inject, Injectable } from '@angular/core';
import { LOCAL_STORAGE, StorageService } from 'ngx-webstorage-service';

@Injectable()
export class VisitCounterService {

  constructor(
    @Inject(LOCAL_STORAGE) private storage: StorageService
  ) {}

  public countVisit(): number {
    const count: number = this.storage.get('visits') || 0
    this.storage.set('visits', count + 1)
    return count
  }
}