2013-05-28 9 views

cevap

13

dönebilirsiniz böylece faktör içinde async işlevi aracılığıyla Sen değer iletebilirsiniz benim fabrikaya benim denetleyicisinden sayfayı göndermek ister y: Normal olarak adlandırılır

var docFactory = { 
    async: function(theVarThatIWantedToPass) { 
     var url=// stuff 
     url += theVarThatIWantedToPass; 
    } 
} 

i tek üretmek için fabrika ve açık pdf dosyalarını ve birçok denetleyicileri her biri kendi url ve dosya geçirerek istiyorum çünkü docFactory.async (sayfa)

-1

denetleyicileri ince tutmak için.

.factory('pdf-service', function($scope, $ionicLoading){ 

if(window.cordova && window.cordova.InAppBrowser){ 
    window.open = window.cordova.InAppBrowser.open; 
    console.log("InAppBrowser available"); 
    } else { 
    console.log("InAppBrowser not available"); 
    } 

    $scope.download = function() { 
    $ionicLoading.show({ 
     template: 'Loading...' 
    }); 
    window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) { 
     fs.root.getDirectory("ExampleProject",{create: true}, 
      function(dirEntry) { 
       dirEntry.getFile(
        "pdf-number-1.pdf", 
        { 
         create: true, 
         exclusive: false 
        }, 
        function gotFileEntry(fe) { 
         var p = fe.toURL(); 
         fe.remove(); 
         ft = new FileTransfer(); 
         ft.download(
          encodeURI("http://www.someservice.com"), 
          p, 
          function(entry) { 
           $ionicLoading.hide(); 
           $scope.imgFile = entry.toURL(); 
          }, 
          function(error) { 
           $ionicLoading.hide(); 
           alert("Download Error Source -> " + error.source); 
          }, 
          false, 
          null 
         );       
        }, 
        function() { 
         $ionicLoading.hide(); 
         console.log("Get file failed"); 
        } 
       ); 
      } 
     ); 
    }, 
    function() { 
     $ionicLoading.hide(); 
     console.log("Request for filesystem failed"); 
    }); 
    } 

    $scope.load = function() { 
     $ionicLoading.show({ 
     template: 'Loading...' 
     }); 

     window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) { 
      fs.root.getDirectory(
       "ExampleProject", 
       { 
        create: false 
       }, 
       function(dirEntry) { 
        dirEntry.getFile(
         "pdf-number-1.pdf", 
         { 
          create: false, 
          exclusive: false 
         }, 
         function gotFileEntry(fe) { 
          $ionicLoading.hide(); 
          $scope.imgFile = fe.toURL(); 
          alert(fe.toURL()); 
          window.open(fe.toURL(), '_system', 'location=no,toolbar=yes,closebuttoncaption=Close PDF,enableViewportScale=yes'); 
         }, 
         function(error) { 
          $ionicLoading.hide(); 
          console.log("Error getting file"); 
         } 
       ); 
       } 
     ); 
     }, 
     function() { 
      $ionicLoading.hide(); 
      console.log("Error requesting filesystem"); 
     }); 
    } 
}); 
:

Bu

dosya transferi ve inappbrowser cordova eklentiler kullanır nic Raboy öğretici https://blog.nraboy.com/2014/09/manage-files-in-android-and-ios-using-ionicframework/ gelen fabrika
İlgili konular