quma
quma

Reputation: 5719

AngularJS leave page

I use AngualrJS for my frontend, before navigating to a page in my routes.js there is a resolve where I can initialize variables needed for controller.

Actually I need the oposite of them - if I leave a page than a method should be invoked, because I use websocket/sockjs and I will switch of the ping if chat page is leaved.

Is there any possibility to do this?

Thanks a lot!

(function() {
'use strict';

angular
    .module('myProject.chat')
    .controller('ChatController', ChatController);

ChatController.$inject = ['$scope', '$state', '$location', '$http', '$timeout', ...];

function ChatController($scope, $state, $location, $http, $timeout, ...) {
    $scope.vm = this; 
    var vm = this;


vm.stompClient.subscribe('/topic/chat/' ...

Upvotes: 0

Views: 64

Answers (1)

charlietfl
charlietfl

Reputation: 171690

There is a destroy event you can use

$scope.$on('$destroy', function(){
  // do cleanup
});

Upvotes: 1

Related Questions