AngularJS在函数执行之后(答应?)

时间:2018-11-13 03:12:44

标签: javascript angularjs

我只想在for循环完成后才执行$ window。我怎么做?我是否必须增加承诺?如果是这样,我该怎么做?我试图看一些有希望的问题,但我不太了解。非常感谢您的帮助和感谢!

 var getAllTheme = displayAll.callAll()
     .then(function(response) {
         $scope.allTheme = response;
         for (var i =0; i < $scope.allTheme.length; i++) {
           if ( i > 0) {
                $scope.themename.push($scope.allTheme[i].THEMENAME);
           }
         }
     })


       $scope.searchFunction = function() {
          for ( var i = 0; i < $scope.allTheme.length; i++) {
              if ($scope.selected == $scope.allTheme[i].THEMENAME)
              {
                  $scope.selectedTheme = $scope.allTheme[i].QUERYNAME;
                  apiURL = 'url';
                  $scope.selected = $scope.allTheme[i].THEMENAME;
                      $http.get(apiURL).then(function(response) {
                        $scope.apiResult = response.data.SrchResults;
                        $scope.apiResult.splice(0,1);
                        for (var i= 0; i < $scope.apiResult.length; i++) {
                             $scope.dataLatLng.push($scope.apiResult[i].LatLng)
                        }

                      })
                      $window.location.href = "#!/searchedResult";
              }


          }

       }

HTML:

<input type="text" class="searchFeature" ng-model="selected"
       ng-keyup="$event.keyCode == 13 && searchFunction()"
       uib-typeahead="value for value in themename | filter:$viewValue | limitTo:7" 
       placeholder="Start your search here.">

0 个答案:

没有答案