我遇到了$ 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
设置它在整个控制器中更新了......