How to create a AngularJS promise from a callback-based API

前端 未结 2 1882
执念已碎
执念已碎 2020-12-02 02:46

wifiservice.js:

angular.module(\'app.WifiServices\', [])
    .factory(\'WifiService\', function(){
        var unique_array = angular.fromJson(\'[]\');

             


        
2条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-02 03:15

    Well, I came up with something different:

    var unique_array = [];
      $scope.wifiList = [];
      $ionicLoading.show({
        template: "Scanning surrounding AP's..."
      });
    
     window.setTimeout(function() {
      $scope.wifiList = WifiService.list();
      // alert($scope.wifiList);
      while ($scope.wifiList == []) {
        console.log('Scanning...');
      }
      $scope.$apply();
      $ionicLoading.hide();
     }, 5000);
    

    What I realize is that the scanning starts once I load the view. So, I added an IonicLoader to force the user to wait, and not be able to press any buttons till the scan is finished. So no function shall wait one another. Not quite code-wise correct, but it does what I need.

提交回复
热议问题