Best way to read Angularjs in an Ionic app

Asked

Viewed 102 times

0

I’m with a question of apps architecture.

I have an IONIC project where the app saves some basic data in Storage location so you don’t have to ask for user login every time it opens.

But this data is essential for the rest of the application.

currently I have the following entry routes:

  • 'app.home' -> when data already exists in localstorage
  • 'app.login' -> when data does not exist and login is required.

the deal is that it is on the route 'app.home' that I do the localstorage check and decide whether to stay on the route or direct to 'app.login'. Except that in the 'app.home' I already need data that should be in the localstorage, and when redirects to login and then back to home, this view had already been loaded and the data saved after login do not update this view.

So I thought, 'what would be the best way to do, then, this data preloader and direct to login or home with the need?'.

That’s the question.

1 answer

0


It’s not "on the route" that you do the localStorage check, it’s in her controller. See, you’re running a code that doesn’t belong to the controller in question.

It would be better to define which route to load before entering a specific controller:

angular.module('App', [ 'ionic',...])

.run(function($state) {

     //faça sua pesquisa na localstorage aqui
     if ( ... ) {
            $state.go('app.home');
     else {
            $state.go('app.login');
     }

});

Browser other questions tagged

You are not signed in. Login or sign up in order to post.