I hope to be able to use time to determine whether the data is retrieved through the interface again or directly retrieved from localstorage. However, the interface returns a promise object. If you use if else to determine whether it will report promise.then is not a function .
Take a time point after the page is loaded, and then take the time when you click refresh. Look at the time difference to determine whether to use local or interface. The logic of the two is different, so they need to be called in different ways. Finally, assign the value to the variable that stores the data on the page, so that the error you mentioned will not occur.
Supplement:
For example, your page data is stored using
$scope.data
.Go to the time point when loading the page and store it in the start variable.
When you click refresh, get the end time and save it as end. You can also get the time difference directly. If the time difference is greater than or equal to one minute, retrieve the data from the interface. Otherwise, get data from localStorage.
The interface retrieves data and returns a promise, while localStorage returns a string.
The code only displays logic and cannot be run directly.