Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs 在forEach完成后调用函数_Angularjs - Fatal编程技术网

Angularjs 在forEach完成后调用函数

Angularjs 在forEach完成后调用函数,angularjs,Angularjs,我有一个方法,只有在forEach块完成执行后才需要调用它。现在在我的代码中,函数在我的forEach块执行之后首先被调用。这是一段代码 function processData(data) { angular.forEach(data.ITINERARY.LIST_BOUNDS, function(bound, boundIndex) { angular.forEach(bound.LIST_SEGMENT, function(segment, index)

我有一个方法,只有在forEach块完成执行后才需要调用它。现在在我的代码中,函数在我的forEach块执行之后首先被调用。这是一段代码

function processData(data) {
      angular.forEach(data.ITINERARY.LIST_BOUNDS, function(bound, boundIndex) {
            angular.forEach(bound.LIST_SEGMENT, function(segment, index) {
                $q.all([
                        ServiceLocationAssistant.getAirport(segment.ORIGIN.LOCATION_CODE),
                        ServiceLocationAssistant.getAirport(segment.DESTINATION.LOCATION_CODE)
                    ])
                    .then(function(locations) {
                        segment.ORIGIN.location = locations[0];
                        segment.DESTINATION.location = locations[1];
                    });
            });
          });
         $scope.flightSection(processedData);//This method needs to be called
    }

不,foreach肯定会在它之后的
flightSection
调用之前执行。承诺很可能会晚些完成,不是吗?!我们需要更多地了解异步代码需要做些什么,才能在这里提出一个好的解决方案。我必须在每个块中使用一些值来设置JSON,然后我必须在Flight部分中对更改后的JSON执行一些操作。