1

コントローラーのコードを以下に示します。これを解決する正しい方法は何ですか?

$scope.photoData = [];
$cordovaImagePicker.getPictures(options).then(function (results) {
  for (var i = 0; i < results.length; i++) {
    $scope.photoData.push(results[i]);
    console.log(results[i]);
    window.plugins.Base64.encodeFile(photoData, function(base64) {
      console.log('photoData: ' + base64);
    });
  }


  if (!$scope.$$phase) {
    $scope.$apply();
  }
}, function (err) {
  // An error occured. Show a message to the user
});

コードを見る

    <ion-slide ng-repeat="item in photoData">
    <img ng-src="data:image/jpg;base64,{{item}}" style="max-width: 100%">
  </ion-slide>
4

1 に答える 1

0

ループが始まる前に関数を宣言できます

$cordovaImagePicker.getPictures(options).then(function(results) {
    function successFunc(base64) {
        console.log('photoData: ' + base64);
    }

    for (var i = 0; i < results.length; i++) {
        $scope.photoData.push(results[i]);
        console.log(results[i]);
        window.plugins.Base64.encodeFile(photoData, successFunc);
    }
    if (!$scope.$$phase) {
        $scope.$apply();
    }
}, function(err) {
    // An error occured. Show a message to the user
});
于 2016-01-07T06:55:13.693 に答える