URL更改后如何重新加载组件Angular 6

时间:2019-01-09 12:39:33

标签: angular ecmascript-6 routing

我需要一个技巧,在URL更改后如何重新加载组件。现在,它只加载一次,因此更改显示一个图块(此组件的元素)取决于URL无效。我尝试了ActivatedRoute,但没有成功。

我的代码:

import { Component, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { WindowRef } from '../../../shared/services/window-ref.service';
import { TranslateService } from '@ngx-translate/core';
import { Location } from '@angular/common';
import { ActivatedRoute } from '@angular/router';
import { find } from 'lodash';

@Component({
  selector: 'lex-user-zone',
  templateUrl: './user-zone.component.html',
  styleUrls: ['./user-zone.component.scss']
})

export class UserZoneComponent implements  OnDestroy, OnInit {
  @Input() preferencesMenu: any;
  @Input() borgSessionId: string;
  @Input() showIntro: () => void;
  @ViewChild('wkLimboPlaceholder') wkLimboPlaceholder: ElementRef;
  wkLibmoCustomLabels: any;

  constructor(
    private windowRef: WindowRef,
    private translateService: TranslateService,
    private location: Location,
    private activatedRoute: ActivatedRoute,
  ) {}

  ngOnInit(): void {
    const wkLimbo = (<any>this.windowRef.nativeWindow).WkLimbo;

    this.getWkLibmoCustomLabels().then((translations: any) => {
      this.wkLibmoCustomLabels = translations;
      if (wkLimbo && wkLimbo.Menu) {
        this.wkLimboReadyEventHandler();
      } else {
        this.windowRef.nativeWindow.addEventListener('wk-limbo-ready', () => {
          this.wkLimboReadyEventHandler();
        });
      }
    });
  }

0 个答案:

没有答案