Search code examples
nativescriptnativescript-angular

Difference between using a service (Angular) and using NativeScript's application-settings


I am working on a simple mobile app with Angular and NativeScript. I can't seem to understand the difference between using an Angular service to share information between components and using NativeScript's applications-settings. They both seem to do very similar things.

I started using a service to store information such as userId, username, phoneNumber, name, jobTitle, etc., which get retrieved in most of the components I am using. That is working fine; however, I just discovered that I could do the same with the application-settings module.

When should I use a service and when should I use application-settings? What is the most efficient approach?


Solution

  • Angular Services save data in the application life cycle, it means if you close the app, the data will not exist anymore.

    But if you want to save data and use them whenever you want to open the app, you can use application-settings. It's actually a native module. The module uses SharedPreferences on Android and NSUserDefaults on iOS. It's something like localStorage on the web.