How does popover $destroy work?

I’m using the popover in ionic, based on the docs here: http://ionicframework.com/docs/api/service/$ionicPopover/

There, you can find an example that goes like this:

$scope.$on('$destroy', function() {
    $scope.popover.remove();
  });

I’m not sure where the $destroy is coming from. Can somebody explain to me how this works?

Thanks a lot for helping out!