@angular/router#ActivationEnd TypeScript Examples

The following examples show how to use @angular/router#ActivationEnd. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: managehttp.interceptor.ts    From barista with Apache License 2.0 6 votes vote down vote up
constructor(router: Router, private httpCancelService: HttpCancelService) {
    router.events.subscribe((event) => {
      // An event triggered at the end of the activation part of the Resolve phase of routing.
      if (event instanceof ActivationEnd) {
        // Cancel pending calls
        this.httpCancelService.cancelPendingRequests();
      }
    });
  }
Example #2
Source File: settings.effects.ts    From enterprise-ng-2020-workshop with MIT License 6 votes vote down vote up
setTitle = createEffect(
    () =>
      merge(
        this.actions$.pipe(ofType(actionSettingsChangeLanguage)),
        this.router.events.pipe(
          filter((event) => event instanceof ActivationEnd)
        )
      ).pipe(
        tap(() => {
          this.titleService.setTitle(
            this.router.routerState.snapshot.root,
            this.translateService
          );
        })
      ),
    { dispatch: false }
  );
Example #3
Source File: examples.effects.ts    From enterprise-ng-2020-workshop with MIT License 6 votes vote down vote up
setTitle = createEffect(
    () =>
      merge(
        this.actions$.pipe(ofType(actionSettingsChangeLanguage)),
        this.router.events.pipe(
          filter((event) => event instanceof ActivationEnd)
        )
      ).pipe(
        tap(() => {
          this.titleService.setTitle(
            this.router.routerState.snapshot.root,
            this.translateService
          );
        })
      ),
    { dispatch: false }
  );
Example #4
Source File: examples.effects.spec.ts    From enterprise-ng-2020-workshop with MIT License 4 votes vote down vote up
describe('SettingsEffects', () => {
  let router: any;
  let titleService: jasmine.SpyObj<TitleService>;
  let translateService: jasmine.SpyObj<TranslateService>;
  let store: jasmine.SpyObj<Store<State>>;

  beforeEach(() => {
    router = {
      routerState: {
        snapshot: {
          root: {}
        }
      },
      events: {
        pipe() {}
      }
    };

    titleService = jasmine.createSpyObj('TitleService', ['setTitle']);
    translateService = jasmine.createSpyObj('TranslateService', ['use']);
    store = jasmine.createSpyObj('store', ['pipe']);
  });

  describe('setTranslateServiceLanguage', () => {
    it('should not dispatch action', () => {
      const actions = new Actions<any>();
      const effect = new ExamplesEffects(
        actions,
        store,
        translateService,
        router,
        titleService
      );
      const metadata = getEffectsMetadata(effect);
      expect(metadata.setTranslateServiceLanguage.dispatch).toEqual(false);
    });
  });

  describe('setTitle', () => {
    it('should not dispatch action', () => {
      const actions = new Actions<any>();
      const effect = new ExamplesEffects(
        actions,
        store,
        translateService,
        router,
        titleService
      );
      const metadata = getEffectsMetadata(effect);

      expect(metadata.setTitle.dispatch).toEqual(false);
    });

    it('should setTitle', () => {
      scheduler.run((helpers) => {
        const { cold, hot } = helpers;
        const action = actionSettingsChangeLanguage({ language: 'en' });
        const actions = hot('-a', { a: action });

        const routerEvent = new ActivationEnd(router.routerState.snapshot);
        router.events = cold('a', { a: routerEvent });

        const effect = new ExamplesEffects(
          actions,
          store,
          translateService,
          router,
          titleService
        );

        effect.setTitle.subscribe(() => {
          expect(titleService.setTitle).toHaveBeenCalled();
          expect(titleService.setTitle).toHaveBeenCalledWith(
            router.routerState.snapshot.root,
            translateService
          );
        });
      });
    });
  });
});