1

The controller code is given below. What is the correct way to solve this?

$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
});

view code

    <ion-slide ng-repeat="item in photoData">
    <img ng-src="data:image/jpg;base64,{{item}}" style="max-width: 100%">
  </ion-slide>
Divya G
  • 49
  • 1
  • 8
  • 1
    Welcome to StackOverflow! Pro tip: Search the site for your problem first so we can keep all the good answers in one place! [Here's your question](http://stackoverflow.com/questions/3037598/how-to-get-around-the-jslint-error-dont-make-functions-within-a-loop). – ruffin Jan 07 '16 at 13:40

1 Answers1

0

You can declare the function before the loop begins

$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
});
Marc
  • 6,051
  • 5
  • 26
  • 56
  • Thank you so much. The error is solved. But i am not able to display the array of images i choose. I have updated with the view code. Any suggestion would be appreciable. – Divya G Jan 07 '16 at 08:53
  • I have literally no experience with Angular. I just came here to solve your JSLint error. – Marc Jan 07 '16 at 09:01