opitzconsulting / jquery-mobile-angular-adapter

jquery mobile angular adapter
MIT License
517 stars 114 forks source link

$destroy event for controller $scope not getting fired #231

Open asgeo1 opened 11 years ago

asgeo1 commented 11 years ago

Hi @tbosch,

When does the $scope for a jqm page get destroyed?

I'm doing something like this in my controller:

var tagRead = function(event) {
  $scope.$apply(function(){
    $scope.searchPlantId = event.tag;
  });
}

$window.addEventListener('tagread', tagRead, false);

$scope.$on('$destroy', function() {
  $window.removeEventListener('tagread', tagRead);
});

In normal AngularJS, when I navigate to a new page, the ng-view directive will ensure that the $scope for the previous view/controller is cleaned up, i.e. by firing the $destroy event.

With jqm-angular-adapter, that does not seem to be the case, and $destroy is never fired when navigating to a new page.

Any reason why? I'm not really understanding what's going on here with jqm-angular-adapter.

Cheers, -adam