Reputation:
How to fix the issue? cause I'm trying to console the elapsed and remaining when I try to reload and it will continue the time. but I'm getting an error which is the :
Argument of type 'number' is not assignable to parameter of type 'string'.
The right-hand side of an arithmetic operation must be of type 'any', 'number', 'bigint' or an enum type.
An argument for 'value' was not provided.
Here's the full code:
LIST = [{
"id": "1lqgDs6cZdWBL",
"timeUpdated": "2020-04-22 12:51:23",
"status": "CLOSED"
}, {
"id": "C2Zl9JWfZHSJ",
"timeUpdated": "2020-04-22 12:51:07",
"status": "CLOSED"
}, {
"id": "BHbiVcCaQa2d",
"timeUpdated": "2020-04-15 14:53:12",
"status": "CLOSED"
}];
ngOnInit() {
this.initializeAlertTimer();
}
initializeAlertTimer(data?: any, duration?: any) {
const DURATION = duration < 0 ? 1000 : duration;
localStorage.setItem('DURATION', DURATION);
localStorage.setItem('start', Date.now());
const elapsed = Date.now() - localStorage.getItem('start');
const remaining = localStorage.setItem('DURATION')
setTimeout(() => {
}, DURATION)
}
addData() {
const data = {
"id": "qHFw59mujN9X",
"timeCreated": "2020-03-06 12:21:06",
"status": "NEW",
}
this.initializeAlertTimer(data, 20000);
}
also what I'm trying to do here is when opening the application it will list all the data LIST from the console once even it will change a page or reload the page it shouldn't repeat and when clicking on the addData() it will add the new data then by initializeAlertTime() it will display the newest data.
Upvotes: 1
Views: 1288
Reputation: 5205
You can only store string
s in localstorage
. Try this:
localStorage.setItem('start',JSON.stringify(Date.now()));
And then:
const elapsed = Date.now() - JSON.parse(localStorage.getItem('start'));
Upvotes: 0
Reputation: 86740
Try this -
const elapsed = Date.now() - (+localStorage.getItem('start'));
Upvotes: 1