0

私のコントローラーには、次の呼び出しがあります。

optionService.init($scope);
optionService.getSubjects1($scope);
optionService.getSubjects2($scope);
optionService.getAbc($scope);

optionService のコードは次のとおりです。

angular.module('common')
    .factory('optionService',
    ['$http',function ($http) {
        var factory = {
            init: function ($scope) {
                $scope.option = {};
            },
            getSubjects1: function ($scope) {
                var url = '/api/Subject1/GetSelect';
                $scope.loading++;
                $http.get(url)
                    .success(function (data, status, headers, config) {
                        $scope.option.subjects1 = data;
                        $scope.loading--;
                    })
                    .error(function (data, status, headers, config) {
                        $scope.loading--;
                        alert("Error: No data returned from " + url);
                    });
            },
            getSubjects2: function ($scope) {
                var url = '/api/Subject2/GetSelect';
                $scope.loading++;
                $http.get(url)
                    .success(function (data, status, headers, config) {
                        $scope.option.subjects2 = data;
                        $scope.loading--;
                    })
                    .error(function (data, status, headers, config) {
                        $scope.loading--;
                        alert("Error: No data returned from " + url);
                    });
            },
        }
        return factory;

    }]);

getSubjects1 と getSubjects2 の両方の呼び出しの完了に依存して、optionService.getAbc への呼び出しを行う方法はありますか? これが違いを生む場合は、すぐにAngular 1.2も使用します。

4

2 に答える 2