TypeError: Object [object Object] has no method 'getFile' - Ionic

半城伤御伤魂 提交于 2019-12-10 12:26:44

问题


I have the below code to get json data and store it in a storage space in the device,I have tried the below code,

 ionic.Platform.ready(function() {

     $cordovaFile.createFile(cordova.file.applicationStorageDirectory, 'file.txt', true)
     $ionicLoading.show();
     $http.post("http://example.com/data/get_data").
     success(function(data) {

         //console.log(data);
         $ionicLoading.hide();

         $cordovaFile.writeFile(cordova.file.applicationStorageDirectory + 'file.txt', data, {
             'append': false
         }).then(function(result) {
             alert('success');
         }, function(err) {
             // An error occured. Show a message to the user
             console.log(JSON.stringify(err));
             alert('failed');
         });

     })

     .error(function(data) {
         console.log("Request failed");
     });

 });

And it is showing an error in console like below :

4 238102 log Error in Success callbackId: File305293268 : TypeError: Object [object Object] has no method 'getFile'

5 238107 error Uncaught TypeError: Object [object Object] has no method 'getFile', http://192.168.2.86:8100/cordova.js, Line: 314

How to solve this?

来源:https://stackoverflow.com/questions/37743522/typeerror-object-object-object-has-no-method-getfile-ionic

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!