$digest already in progress when i use ionicplatform.ready with camera functionality
<p>This is my controller, i am trying to capture image with a button in page 1 and store it locally, and display image1 in page 1, then if i click the button again to take the pic of image2. Image2 should be displayed in page1 and image1 should be viewed in page2</p>

<pre><code>.controller('LeadDetailController', [
            '$scope', 
            '$cordovaDevice',
            '$cordovaFile',
            '$ionicPlatform',
            'ImageService', 'FileService',
function(   $scope, 
            $cordovaDevice,
            $cordovaFile,
            $ionicPlatform,
            ImageService, FileService) {
 // image capture code
    $ionicPlatform.ready(function() {
         console.log('ionic is ready');
        $scope.images = FileService.images();
        $scope.$apply();
    });

    $scope.urlForImage = function(imageName) {
        var trueOrigin = cordova.file.dataDirectory + imageName;
        return trueOrigin;
    }

    $scope.addImage = function(type) {
        ImageService.handleMediaDialog(type).then(function() {
          $scope.$apply();
        });
    }
</code></pre>

<p>at the initial stage itself i am getting this error </p>

<blockquote>
  <p>Error: [$rootScope:inprog] $digest already in progress</p>
</blockquote>

<p>page1 with buttons</p>

<pre><code>// here camera function is called to open the camera and take pic
&lt;ion-option-button ng-click="addImage()"class="icon ion-android-camera"&gt;&lt;/ion-option-button&gt;
//here the pic taken in camera should be displayed 
&lt;ion-option-button&gt; 
      &lt;img src=""&gt;       
&lt;/ion-option-button&gt;
//here moveing to the next page2
&lt;ion-option-button ng-click="Page2()" class="icon ion-ios-grid-view"&gt;&lt;/ion-option-button&gt;
</code></pre>

<p>page2 html </p>

<pre><code>&lt;ion-view&gt;
    &lt;ion-nav-bar class="bar-positive"&gt;
        &lt;ion-nav-title class="title"&gt;Grid View&lt;/ion-nav-title&gt;
    &lt;/ion-nav-bar&gt;
    &lt;ion-content class="has-header"&gt;
        &lt;img ng-repeat="image in images" ng-src="{{image.src}}" ng-click="showImages($index)" style="height:50%; width:50%; padding:2px "&gt;
    &lt;/ion-content&gt;
&lt;/ion-view&gt;
</code></pre>

<p>page2 controller</p>

<pre><code> .controller('gridController', function($scope, $ionicBackdrop, $ionicModal, $ionicSlideBoxDelegate, $ionicScrollDelegate)  {  
//here the images are stored inside the array   
        $scope.images = [{    }];
</code></pre>

<p>services</p>

<pre><code>.factory('FileService', function() {
  var images;
  var IMAGE_STORAGE_KEY = 'images';

  function getImages() {
    var img = window.localStorage.getItem(IMAGE_STORAGE_KEY);
    if (img) {
      images = JSON.parse(img);
    } else {
      images = [];
    }
    return images;
  };

  function addImage(img) {
    images.push(img);
    window.localStorage.setItem(IMAGE_STORAGE_KEY, JSON.stringify(images));
  };

  return {
    storeImage: addImage,
    images: getImages
  }
})



.factory('ImageService', function($cordovaCamera, FileService, $q, $cordovaFile) {

  function makeid() {
    var text = '';
    var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

    for (var i = 0; i &lt; 5; i++) {
      text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    return text;
  };

  function optionsForType(type) {
    var source;
   /* switch (type) {
      case 0:
        source = Camera.PictureSourceType.CAMERA;
        break;
      case 1:
        source = Camera.PictureSourceType.PHOTOLIBRARY;
        break;
    }*/
    return {
      destinationType: Camera.DestinationType.FILE_URI,
      sourceType: source,
      allowEdit: false,
      encodingType: Camera.EncodingType.JPEG,
      popoverOptions: CameraPopoverOptions,
      saveToPhotoAlbum: false
    };
  }

  function saveMedia(type) {
    return $q(function(resolve, reject) {
      var options = optionsForType(type);

      $cordovaCamera.getPicture(options).then(function(imageUrl) {
        var name = imageUrl.substr(imageUrl.lastIndexOf('/') + 1);
        var namePath = imageUrl.substr(0, imageUrl.lastIndexOf('/') + 1);
        var newName = makeid() + name;
        $cordovaFile.copyFile(namePath, name, cordova.file.dataDirectory, newName)
          .then(function(info) {
            FileService.storeImage(newName);
            resolve();
          }, function(e) {
            reject();
          });
      });
    })
  }
  return {
    handleMediaDialog: saveMedia
  }
});
</code></pre>

<p>could someone help me to fix this issue and to help me with page2 to imageviewing      </p>