无法显示PERSISTENT storage IONIC中的图像

时间:2016-09-07 09:47:03

标签: angularjs cordova ionic-framework

我正在尝试在我的离子应用中使用$ cordovaFile插件显示PERSISTENT存储中的图像。

我的代码:

controller('surveyLoad', function($q, $cordovaFile, $rootScope, $scope, $ionicLoading, localStorageService, $state, surveyApi, AppConfig, ionicDatePicker){

var QuestionIndex = 0;

window.answerData = '';

if($state.params.surveyId == 1){

    var SurveyData = localStorageService.get('SurveyData');
    console.log(localStorageService.get('SurveyData'));

}else if($state.params.surveyId == 2){

    var SurveyData = localStorageService.get('SurveyData2');
    console.log(localStorageService.get('SurveyData2'));
}

var totalQuest = Object.keys(SurveyData).length

$scope.totalQst = totalQuest+1;  //Set Total Question Value in Survey.html

if($state.params.QuestId.trim() != ''){

    QuestionIndex = $state.params.QuestId;
}

$scope.currentQst = parseInt(QuestionIndex)+1; //Set Current Question number in Survey.html

//if Survey According to Question Order
if(AppConfig.QuestionOrder == 'true'){

    angular.forEach(SurveyData, function(value, key) {
        if(value.question_order == QuestionIndex){

            var paramQid = key;
            var QuestionID = value.question_id;
        }
    });
}
//end here
var QuestType  =  SurveyData[QuestionIndex].question_type;
//var QuestImage =  '<img src="img/gaph.png" alt="" class="qimg">';
var DrawHTML = {
                  'QuestionText': SurveyData[QuestionIndex].question_text, 
                  'QuestionDesc': SurveyData[QuestionIndex].question_desc,
                  'QuestAnswers': SurveyData[QuestionIndex].answers,
                  'scope'       : $scope,
                  'raw'         : SurveyData[QuestionIndex]
               };

switch(QuestType){

    case'text':
        text(DrawHTML, ionicDatePicker, $q, $rootScope, $cordovaFile);
    break;

    case'textarea':
        textarea(DrawHTML);
    break;

    case'number':
        number(DrawHTML);
    break;

    case'email':
        email(DrawHTML);
    break;

    case'radio':
        radio(DrawHTML);
    break;

    case'checkbox':
        checkbox(DrawHTML);
    break;

    case'select':
        select(DrawHTML);
    break;
}

});

function text(params, ionicDatePicker, $q, $rootScope, $cordovaFile){
     $scope.QuesHtml = "<p>"+params.QuestionText+"</p>";
     $scope.DescHtml = "<p>"+params.QuestionDesc+"</p>";

     var fname = "SmaartMedia/jellyfish.jpg";
       $cordovaFile.checkFile(cordova.file.externalRootDirectory, fname)
          .then(function(obj) {
           $scope.image_1 = obj.nativeURL;
          $scope.$apply();
      }, function(error) {
          alert(error.code);
      });
}

survey.html

<p>Sample for media and captcha <img ng-src={{image_1}} />  <img ng-src={{image_2}} /></p>

我不知道为什么我在cordova.file.externalRootDirectory上收到错误。在控制台中显示(甚至在移动设备上)

  

无法读取未定义

的属性'externalRootDirectory'

任何人都可以告诉我代码中的问题在哪里?

由于

0 个答案:

没有答案