Angular 在加载ionic3链接页面之前,请等待事件

Angular 在加载ionic3链接页面之前,请等待事件,angular,ionic3,Angular,Ionic3,我有一个Ionic3/Angular4应用程序,数据来源取决于当前登录的用户,因此我必须等待触发用户数据事件来设置数据连接。(我使用firebase来管理用户身份验证) 在主要部分中,我有以下内容: async ngOnInit() { this.afAuth.authState.subscribe(async data => { if (data && !data.isAnonymous) { await this.user

我有一个Ionic3/Angular4应用程序,数据来源取决于当前登录的用户,因此我必须等待触发用户数据事件来设置数据连接。(我使用firebase来管理用户身份验证)

在主要部分中,我有以下内容:

  async ngOnInit() {
    this.afAuth.authState.subscribe(async data => {
      if (data && !data.isAnonymous) {    
        await this.userService.initSettingsAsync(data.uid);
      }
      else {
        this.nav.setRoot('LoginPage');
      }
    });
  }
我的页面是:

@IonicPage({
  segment: 'customers/:customerId',
  defaultHistory: ['CustomersPage'],
})
@Component({
  selector: 'page-customer-detail',
  templateUrl: 'customer-detail.html',
})
export class CustomerDetailPage {
  customerId: string;
  customer: Customer;

  constructor(public navParams: NavParams, private customerService: CustomerService) {
    this.customerId = navParams.get("customerId");
  }

  async ionViewDidLoad() {
    console.log('ionViewDidLoad CustomerDetailPage');
    this.customer = await this.customerService.get(this.customerId);
  }
}
this.customerService.get(this.customerId)
必须在
this.userService.initSettingsAsync(data.uid)
promise得到解析,否则userService不知道从哪里获取数据

当页面由deeplink加载时,它会在authState事件触发之前被初始化


我怎样才能巧妙地处理这个问题?我的意思是,我不喜欢把用户的东西放在每个需要数据的页面上。

当初始化完成时,添加离子导航就足够了。超级容易;) 希望这有帮助

app.html:

<ion-nav *ngIf="initialized" [root]="rootPage" #content></ion-nav>
由于初始化后将“nav”添加到视图中,因此需要一些技巧():

  async ngOnInit() {
    this.afAuth.authState.subscribe(async data => {
      if (data && !data.isAnonymous) {    
        await this.userService.initSettingsAsync(data.uid);
        this.initialized = true;
      }
      else {
        this.initialized = true;
        setTimeout(() => this.openPage('LoginPage'));
      }
    });
  }
  private nav: Nav;
  @ViewChild(Nav) set contnav(nav: Nav) {
    this.nav = nav;
  }