Search code examples
ionic-frameworkionic-view

ionic factory not open other url


i have an ionic modal that have button to allow user open other page while this modal have jrcrop

my sample

angular.module('ionicApp', ['ionic']).controller('cropCtrl', function($http,$scope, $ionicModal, $jrCrop) {
        $jrCrop.crop({
          url: 'img.jpg',
          width: 200,
          height: 200,
        })
        .then(function(canvas) {
          $ionicModal.fromTemplateUrl('result-cropped.html', function(modal) {
            $scope.modal = modal;

            modal.show().then(function() {
              document.querySelector('.cropped-canvas').appendChild(canvas);
            });
          });
        });

    }).factory("$jrCrop",["$ionicModal","$rootScope","$q",function(t,i,e)

{..........................
,openpage:function(){$scope.go('images');}
...................
    }]);

and i have error says

$scope is not defined


Solution

  • It is undefined because you never defined it:

    factory("$jrCrop",["$ionicModal","$rootScope","$q",function(t,i,e)
    

    But you don't even want to use $scope inside a factory. You would access whatever is needed from the factory inside a controller which has access to $scope.

    Look at this stack: Accessing $scope in AngularJS factory?

    Also: You write $scope.go('images'); as if it should be $state.go('images'); unless you have a $scope function called go(). But, again you shouldn't be using either of those in the factory.