javascript - Resolve services in app.run, bad logic? -



javascript - Resolve services in app.run, bad logic? -

i discovered issue doing service calls in .run method. seems controllers doesn't wait services resolve before moving on

.run(['user', 'translation', function(user, translation) ... service injection

get user:

$rootscope.user = user.get();

get translation based on users preferred language

$rootscope.user.$promise.then(function(user) { $rootscope.translation = translation.language(user.user_language.tolowercase()).then(function(translation) { $rootscope.translation = translation.data; }); intercom , other stuff... });

in controller set property on object translation like

$scope.obj = { prop: $scope.translation.prop }

this fails 10% of times, i'm guessing, due fact language services hasn't been resolved yet.

all initialization of stuff intercom, segment.io based on info user, thats tried language resolved in .run

the question should instead. seems repetive resolve services on every state (ui-router) in application.

you may want create abstract route root state app , resolve route wide-app data. if causes lot of problem refactoring may want check john papa course.

i remember him mentioning solution in lastly course:

angularjs-patterns-clean-code

you can utilize pluralsight trial period consume of course of study free. sorry not remembering solution right now.

javascript angularjs

Comments

Popular posts from this blog

php - How to pass multiple values from url -

database - php search bar when I press submit with nothing in the search bar it shows all the data -

ios - How to load .png images from Documents folder of an app -