从JSON上的$ http.get更新范围变量

时间:2015-07-28 11:00:56

标签: javascript html json angularjs angularjs-scope

我遇到了$ scope变量未更新的问题:

在我的控制器中我有:

$scope.frCartoList = [];
$scope.enCartoList = [];
$scope.cartoList = [];
$scope.filteredCartoList = [];

$scope.loadJSON = function () {
        $http.get("SVG/fr/cartoList.json")
            .success(function (data) {
                $scope.frCartoList = data;
            })
            .error(function () {
                console.log("Error while getting french json.");
            });

        $http.get("SVG/en/cartoList.json")
            .success(function (data) {
                $scope.enCartoList = data;
            })
            .error(function () {
                console.log("Error while getting english json.");
            });
        $scope.setDefaultSearch();
        $scope.getAreaFilters();
        $scope.getBlockFilters();

        if ($scope.shared)
            $scope.homeVisible = false;
        console.log($scope.enCartoList);
    };

    $scope.setJSON = function () {
        if ($scope.isEnglish)
            $scope.cartoList = $scope.enCartoList;
        else if ($scope.isFrench)
            $scope.cartoList = $scope.frCartoList;

        console.log($scope.enCartoList);

        $scope.initMenu();
        $scope.filteredCartoList = $scope.cartoList.filter($scope.search);
    };

$scope.loadJSON();
$scope.setJSON();

但我的$scope.enCartoList和我的$scope.frCartoList仅在$http.get内有正确的值 我想,这不是使用的主要$scope或者其他东西,但这很奇怪,因为在此之前我只有一个$scope.cartoList我曾经在$scope.loadJSON设置它在整个控制器中更新了......

0 个答案:

没有答案