0

在我的标题组件中,我有一个登录按钮,可以让我登录到第三方网站。应用程序 sc2 在标头组件中使用 callbackURL 进行初始化。在标题中,我得到了一个用于连接到 sc2 的 LoginURL。我可以向 loginURL 添加一个状态,在我的情况下,它只是一个带有我所在当前页面的 id 的字符串,它在回调 URL 的参数中返回。问题是 Header 永远不会随状态更新,因为回调 URL 调用主组件(在路由器插座中加载) 标头本身加载在主组件之上。我无法让主要组件重新路由到原始组件。在我将按钮从主组件移动到标题组件之前,它一切正常,现在发送到主组件的状态没有更新到最后一页,所以我不能通过主要组件将它重新路由到原始组件。正在使用的页面。我尝试了 messageService 并使用了 localStorage,但好像标头组件永远不会按时更新。回调 URL 始终指向主组件。我可以直接与 Header 组件对话吗?

应用程序组件

  <app-header> </app-header>

  <router-outlet> </router-outlet>


  this.api = sc2.Initialize({
  app: 'someName.app',
  //  callbackURL: 'http://localhost/main/',
  callbackURL: this.callBackURL,
  accessToken: this.accessToken,
  scope: ['vote', 'comment']
 });


 this.loginUrl =  this.api.getLoginURL(this.state)

page.component.ts

     constructor() {
        this.newStateService.setState("page")
        this.newStateService.setCoinId("pageId")
        this.newStateService.changeMessageCoinId(this.coinId)
            const params = new HttpParams().set('_id', this.coinId);
       }

头组件.ts

  constructor() {

   this.newStateService.currentMessageState
   .takeWhile(() => this.alive)
  .subscribe(message => { 
  this.state = message
  })


 this.newStateService.currentMessageCoinId
  .takeWhile(() => this.alive)
  .subscribe(message => { 
  this.coinId= message
  })
 this.stateText = newStateService.getState();
 this.coinId = newStateService.getCoinId();  }
4

1 回答 1

0

您面临的区域问题,因此您可以使用此方法

import { ApplicationRef } from '@angular/core';
constructor(
private _applicationRef: ApplicationRef) {}

this.router.navigate(['/router']).then(() => {
    this._applicationRef.tick();
});
于 2018-05-26T19:08:14.350 回答