0

スコープ内のメソッドの定義に関連するいくつかの奇妙な問題があります。定義したら、それを呼び出したいときに (コードに入力するだけで) 消えます。私はコードのこの部分を持っています

if (ConfigurationService.isConfigurationChanged() === true) {
ConfigurationService.getConfiguration().then(function(data) {
    $scope.configuration = data.configuration;
    $scope.lunchers = data.lunchers;

    $scope.configuration.vegies.all_in_one_group = data.configuration.vegies.all_in_one_group;

    var lunchersLength = data.lunchers.all.length;

    for (var i = 0; i < lunchersLength; i++) {
        $scope.selectedVegies[i] = $scope.isVegie(data.lunchers.all[i]);
        $scope.selectedSpecialGroup[i] = $scope.isInSpecialGroup(data.lunchers.all[i]);
        $scope.isAbsent[i] = $scope.isAbsent(data.lunchers.all[i]);
    }   
}); 

} else if (ConfigurationService.isConfigurationChanged() === false)  {

var cached = ConfigurationService.getCachedConfiguration();
console.log($scope.isVegie);
$scope.configuration = cached.configuration;
$scope.lunchers = cached.lunchers;

$scope.configuration.vegies.all_in_one_group = cached.configuration.vegies.all_in_one_group;

var lunchersLength = cached.lunchers.all.length;

for (var j = 0; j < lunchersLength; j++) {
    $scope.selectedVegies[i] = $scope.isVegie(cached.lunchers.all[j]);
    //$scope.selectedSpecialGroup[i] = $scope.isInSpecialGroup(cached.lunchers.all[i]);
    //$scope.isAbsent[i] = $scope.isAbsent(cached.lunchers.all[i]);
}
}

今、何か奇妙なことが起こります。見えますか:

console.log($scope.isVegie);

私が持っているとき:

$scope.selectedVegies[i] = $scope.isVegie(cached.lunchers.all[j]);

コメントしました firebug でメソッドを見ることができます。コメントを外すと、未定義になります...

誰かが同様の問題を抱えていましたか?

ノート:

ConfigurationService.getConfiguration()

この方法ですか:

            getConfiguration : function() {
            var deferred = $q.defer();
            $http({
                    method :'GET',
                    url : "cgi-bin/get_configuration.py"
                })
                .success(function(data, status, headers, config) {
                    if (status === 200) {
                        angular.copy(data, configStatus.currentConfig);// = data;
                        configStatus.configurationChanged = false;
                        deferred.resolve(data);
                    }
                })
                .error(function(data, status, headers, config) {
                    console.log(data);
                    console.log(status);
                    deferred.reject(data);
                });
            return deferred.promise;
        },
4

1 に答える 1