0

テンプレートのヘッダーに表示するユーザーのプロファイル情報を取得するサービスを使用しようとしています。

問題は、サービスが実際に何かを返す前に、コントローラーの変数が設定されていることです (または、少なくともそのように見えます)。

app.js

// This gets the basic information that is needed for every page
myapp.service('base', function($http) {

    this.getProfile = function() {
        // Get the logge din users info
        $http.get(baseUrl+'v1/users?api_key=1234')
            .success(function(response) {
                console.log('base response = '+response);
                return response;
            })  
    }

});

profile.js

myapp.controller('ProfileController', ['$scope', '$http', 'base', function($scope, $http, base) {

    base.getAuthHeader();
    $scope.profile = base.getProfile();
    console.log('$scope.profile = '+$scope.profile);        
}]);

私のfirebugでは、これはこの正確な順序での出力です:

$scope.profile = undefined
base repose = [object Object]

前にどのように行console.log('$scope.profile = '+$scope.profile);が呼び出されconsole.log('base response = '+response);ますか?

4

1 に答える 1