AngularJS - Load factory result during app launch

I have multiple controller files and in of them I am trying to load the result from a factory as soon as the controller is triggered. I am loading the user information. Currently when the page loads, it shows nothing but when I click refresh all information shows.

How can i fix this to eliminate the need for the refresh button?

This is my code in the main body of the controller:

var currentUser = Parse.User.current();    

if (currentUser) {
    // do stuff with the user
    $scope.tempUserObject = UserDetails.overallDetails();
} else {
    // show the signup or login page
    $scope.logout();
}

Answers


you return only promise from Factory. e.g.:

Controller

var currentUser = Parse.User.current();    

if (currentUser) {
    // do stuff with the user
    $scope.tempUserObject = UserDetails.overallDetails().success(function(response){
      console.log(response);
   }).error(function(error){
      console.log("Error = "+error);
   });
} else {
    // show the signup or login page
    $scope.logout();
}

Factory

app.factory('UserDetails', ['$http', function($http){
return {
    overallDetails : overallDetailsFun
 }

function overallDetailsFun(){

  return {
          $http.get("127.0.0.1/api/details");
      }
 }
}]);

Need Your Help

Android : restart application after update - ACTION_PACKAGE_REPLACED

android broadcast

My application that is not on Play Store verify on the web If there are a new version and download and start it. After the installation I would like to restart the application and I would use a

Splitting Hibernate Entity among 2 Tables

java hibernate jpa java-ee orm

I have a simple Class Hierarchy that I am trying to get to work with Hibernate/JPA.