@angular/router#RouterEvent TypeScript Examples

The following examples show how to use @angular/router#RouterEvent. 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: app.component.ts    From TheHungryRecipesApp with GNU General Public License v3.0 6 votes vote down vote up
constructor(
    router: Router,
    private appService: AppService
  ) {
    this.loading = false;
    router.events.subscribe(
      (event: RouterEvent):void => {
        if ( event instanceof NavigationStart ) {
          this.loading = true;
        } else if ( event instanceof NavigationEnd ) {
          this.loading = false;
        }
      }
    );
  }
Example #2
Source File: search-list.component.ts    From ng-ant-admin with MIT License 6 votes vote down vote up
constructor(private searchListService: SearchListStoreService, private activatedRoute: ActivatedRoute,
              private destroy$: DestroyService,
              private router: Router, private cdr: ChangeDetectorRef) {
    this.searchListService.getCurrentSearchListComponentStore().pipe(takeUntil(this.destroy$)).subscribe(componentType => {
      this.pageHeaderInfo = {
        title: componentType,
        desc: this.headerContent,
        footer: this.headerFooter,
        breadcrumb: ['首页', '列表页', componentType]
      };
      this.cdr.markForCheck();
    });
    this.router.events.pipe(
      filter(event => event instanceof NavigationEnd)).subscribe((event) => {
      if (event instanceof RouterEvent) {
        this.currentSelTab = this.tabData.findIndex(item => {
          return item.url === event.url;
        });
      }
    });
  }
Example #3
Source File: app.component.ts    From open-genes-frontend with Mozilla Public License 2.0 6 votes vote down vote up
private handleRouterState(): void {
    this.router.events.pipe(takeUntil(this.subscription$)).subscribe((event: RouterEvent) => {
      if (event instanceof NavigationEnd || event instanceof RouteConfigLoadEnd) {
        // Hide progress spinner or progress bar
        this.currentRoute = event.url;
        if (this.currentRoute === '/404') {
          this.isFooterVisible = false;
        }
        setTimeout(() => {
          this.document.body.classList.remove('body--loading');
        }, 2000);
      }
    });
  }
Example #4
Source File: preview.component.ts    From sba-angular with MIT License 5 votes vote down vote up
constructor(
    @Optional() @Inject(PREVIEW_CONFIG) previewConfig: PreviewConfig,
    @Optional() @Inject(MODAL_MODEL) previewInput: PreviewInput,
    private cdr: ChangeDetectorRef,
    protected router: Router,
    protected route: ActivatedRoute,
    protected titleService: Title,
    protected _location: Location,
    public loginService: LoginService,
    protected intlService: IntlService,
    protected previewService: PreviewService,
    protected searchService: SearchService,
    public prefs: UserPreferences,
    public ui: UIService,
    protected activatedRoute: ActivatedRoute,
    private zone: NgZone
    ) {

    // If the page is refreshed login needs to happen again, then we can get the preview data
    this.loginSubscription = this.loginService.events.subscribe({
      next: (event) => {
        if (event.type === "session-changed") {
          this.getPreviewData();
        }
      }
    });

    // The URL can be changed when searching within the page
    this.routerSubscription = this.router.events
      .pipe(
        filter(event => event instanceof RouterEvent && event.url !== this.homeRoute)
      ).subscribe({
      next: (event) => {
        if (event instanceof NavigationEnd) {
          this.getPreviewDataFromUrl();
        }
      }
    });

    // In case the component is loaded in a modal
    if(previewInput){
      if(previewInput.config){
        previewConfig = previewInput.config;
      }
      this.id = previewInput.id;
      this.query = previewInput.query;
    }

    // Configuration may be injected by the root app (or as above by the modal)
    if(previewConfig){
      this.previewConfig = previewConfig;
    }

    this.tooltipTextActions.push(new Action({
      text: "msg#searchForm.search",
      title: "msg#preview.searchText",
      icon: "sq-preview-search-icon",
      action: (action, event) => {
        if (this.query) {
          this.query.text = event['text'].slice(0, 50);
          this.router.navigate([], {
            relativeTo: this.route,
            queryParams: {query: this.query.toJsonForQueryString()},
            queryParamsHandling: 'merge',
            state: {}
          });
        }
      }
    }));

    titleService.setTitle(this.intlService.formatMessage("msg#preview.pageTitle"));

  }