global_event_srv.ts 629 B

123456789101112131415161718192021
  1. import coreModule from 'app/core/core_module';
  2. import appEvents from 'app/core/app_events';
  3. // This service is for registering global events.
  4. // Good for communication react > angular and vice verse
  5. export class GlobalEventSrv {
  6. /** @ngInject */
  7. constructor(private $location, private $timeout) {
  8. }
  9. init() {
  10. appEvents.on('location-change', payload => {
  11. this.$timeout(() => { // A hack to use timeout when we're changing things (in this case the url) from outside of Angular.
  12. this.$location.path(payload.href);
  13. });
  14. });
  15. }
  16. }
  17. coreModule.service('globalEventSrv', GlobalEventSrv);