ionic-translator/src/app/api/history.service.ts
surtur 821a8505cc
All checks were successful
continuous-integration/drone/push Build is passing
feat: add history functionality
2020-11-24 17:53:23 +01:00

32 lines
663 B
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
import { HistoryRecord } from '../models/history-record.model';
@Injectable({
providedIn: 'root'
})
export class HistoryService
{
historyArray: HistoryRecord[] = []
constructor(private storage: Storage){
storage.get('history').then((val) =>
{
if(val)
{
this.historyArray = JSON.parse(val);
}
});
}
public saveRecord(record: HistoryRecord)
{
this.historyArray.unshift(record);
this.storage.set('history', JSON.stringify(this.historyArray));
}
public getRecord()
{
return this.historyArray;
}
}