进入页面后如何打开侧边菜单?

How to open sidemenu after entering a page?

我正在使用 Google Firestore 构建一个 Ionic4 应用程序,我在其中进行了一些登录。我想要的只是每次登录应用程序时打开的侧边菜单。

类似于:登录 > PageX > *打开侧边菜单。 我该怎么做?

这是应用页面,定义了菜单内容

    <ion-app>

      <ion-menu>

        <ion-header>

          <ion-toolbar color="primary">

            <ion-title>Menu</ion-title>

          </ion-toolbar>

        </ion-header>

        <ion-content>

          <ion-list>

            <ion-item *ngIf="auth.usuario$ | async; then authenticated else guest">

            </ion-item>

            <ng-template #guest>

              <p text-center>Entre Utilizando Suas Credenciais</p>

            </ng-template>

            <ng-template #authenticated>

              <ion-menu-toggle auto-hide="false" *ngFor="let p of appPages">

                <ion-item [routerDirection]="'root'" [routerLink]="[p.url]">

                  <ion-icon slot="start" [name]="p.icon"></ion-icon>

                  <ion-label>
                    {{p.title}}
                  </ion-label>

                </ion-item>

              </ion-menu-toggle>

              <div text-center *ngIf="auth.usuario$ | async as usuario">

                <ion-button color="secondary" (click)="auth.deslogar()">Logout</ion-button>

              </div>

            </ng-template>

          </ion-list>

        </ion-content>

      </ion-menu>

      <ion-router-outlet main></ion-router-outlet>

    </ion-app>

Ionic Side-Menu Documentation 可以看出有一个 .open() 方法可用。

Description: Opens the menu. If the menu is already open or it can't be opened, it returns false.

Signature: open(animated?: boolean) => Promise

在对用户进行身份验证后默认打开侧边菜单的解决方案是使用组件 ngOnInit() 方法中的 .open() 方法。

例如在验证后加载的组件中:

ngOnInit(){
 this.menu.open();
}