离子本地存储VS利用服务 [英] Ionic local storage vs using service

查看:168
本文介绍了离子本地存储VS利用服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现自己把我的所有数据从设备本地存储我的API调用,我不知道,如果它的事项是否我把东西放在本地存储VS把他们的服务。什么时候应该使用本地存储设备,从VS使用Angularjs服务?

I am finding myself placing all my data from my api calls in the device local storage and I am not sure if it matters whether I put things in local storage vs putting them in a service. When should I use local storage from device vs using a Angularjs service?

推荐答案

您有点混到了概念。 当谈到angularjs服务,只要网页不刷新自己保持数据,只要您刷新页面或关闭浏览器选项卡中,数据的消失了。

You are a bit mingled up with concepts. When it comes to angularjs services, they persist data as long as the page is not refreshed, as soon as you refresh your page or close the browser tab, The data's gone.

考虑Angularjs服务,你仅仅是声明的变量,它的作用域到浏览器标签的使用寿命。因此,你可以用它来存储一些临时标志和值并不意味着结转到下一届会议。

Consider Angularjs services as mere variables that you declare, which are scoped to the lifetime of your browser tab. Hence, you can use it to store some temporary flags and values that aren't meant to be carried forward to next session.

然而, 当涉及到本地存储,认为这是一个数据库类的东西。无论在你的localStorage存储,保存在浏览器中,并且将在多个选项卡可用,并且您的应用程序的会话[之前,除非用户清除浏览器数据]

Whereas, When it comes to localStorage, consider it as a database kind of stuff. Whatever you store in localStorage, is saved inside the browser, and will be available across multiple tabs, and sessions of your apps [Until and unless user clears browser data].

由于您使用的离子和科尔多瓦,必须使用localStorage的保存的东西,如用户名和密码,使用户可以他打开你的应用程序下一次使用。拿一张纸条,上面,关闭您的应用程序就相当于关闭浏览器选项卡。

Since you're using Ionic and Cordova, you must use localStorage to save stuff such as user name and password, so that the user can use them the next time he opens your app. Take a note that, closing your app is equivalent to closing a browser tab.

然而,如果你有一个不断刷新,每次用户访问您的应用程序,你可以用服务来存储它们,使它们的应用程序的关闭尽快删除。某些数据

Whereas, if you have certain data that keeps refreshing each time user visits your app, you can use services to store them, so that they are removed as soon as the app's closed.

打个比方,localStorage的 - >中,非易失性存储,angularjs服务 - >主,易失性存储器

这篇关于离子本地存储VS利用服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆