PolarCape/polarcape-cordova-plugin-document-handler

success handler not running angular scope functions

Opened this issue · 1 comments

angularJS v1.*
Ionic v1
built on iOS

The following code will successfully hit the alert but not set the $scope.loading variable to null.

Seems as if $scope is not accessible while viewing the Document Handler. Any ideas around this would be appreciated!

app.controller('CatalogController', function($scope, $firebaseArray, $firebaseObject, CatalogService, $localStorage, $window) {
  $scope.$on('$ionicView.beforeEnter', function () {
  	$scope.loading = true;
		$scope.screen = $window.innerWidth;
  	var issues = CatalogService.getIssues();
		  issues.$loaded().then(function(){
		  	$scope.issues = issues;
		  	$scope.loading = null;  	
	  	});
  	});

  	$scope.viewIssue = function(issue) {
		$scope.loading = true;
                
	  	DocumentHandler.previewFileFromUrlOrPath(function() {
	  		//success
                     alert('success');
		    $scope.loading = null;

	    }, function (error) {
	    	//error
	    	$scope.loading = null;
		    if (error) {
		    	alert('There was a problem loading this issue. Please try again shortly or contact support at *support@email.com.');
		    }
			},
			issue.content, issue.name + '-' + issue.serial);
	  };
});

@krubera
If you are still having this problem, try with $scope.$apply() after changing $scope variable.

From angular 1.x docs(source):

$apply() is used to execute an expression in angular from outside of the angular framework. (For example from browser DOM events, setTimeout, XHR or third party libraries). Because we are calling into the angular framework we need to perform proper scope life cycle of exception handling, executing watches.