Skip to content

@ionic/angular MenuController can't open menu in my Angular app. #3105

@everythingbytesnz

Description

@everythingbytesnz

Stencil version:

 @stencil/core@2.4.0

I'm submitting a:
[x] bug report
[ ] feature request
[ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior:
@ionic/angular MenuController commands can't find any ionic menu programmatically when I add defineCustomElements(); to my main.ts.

The menu can be opened if I add an ion-menu-button element to the UI. https://ionicframework.com/docs/api/menu-button.

I didn't use this solution because we have 3 menus and we have a lot of code to programmatically hide and show them using menuController.open() menuController.close() etc.

Expected behavior:
MenuController should be able to open a ion-menu component in my angular app with this.menuController.open().

Steps to reproduce:

  1. Add stencil web components to Angular project
  2. Modify project according to the Angular guide: https://stenciljs.com/docs/angular
  3. Add ion-menu to angular component
  4. Run this code inside the angular component: menuController.open();
  5. The menu doesn't open (unless you comment out defineCustomElements() from main.ts)
  6. Run this code inside the angular component: this._menuCtrl.getMenus().then(menus => console.log('menus found', menus));
  7. Empty array appears in the console: 'menus found', []

Related code:

app.component.html

<ion-app>
  <ion-router-outlet id="main"></ion-router-outlet>
  <ion-button color="primary" fill="clear" (click)="openMenu()">Click to open</ion-button>
  <ion-menu contentId="main">
    Menu open
  </ion-menu>
</ion-app>

app.component.ts

import { Component } from '@angular/core';
import { MenuController } from "@ionic/angular";

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html',
})
export class AppComponent {
  constructor(private _menuCtrl: MenuController) {}

  async openMenu() {
    this._menuCtrl.getMenus().then(menus => console.log(menus));
    await this._menuCtrl.open();
  }
}

This code should return an array of ionic menu elements but instead returns an empty array.

this._menuCtrl.getMenus().then(menus => console.log('menus found', menus));

This code should open a menu but it doesn't, there is no change to the UI.

this._menuCtrl.open();

Metadata

Metadata

Assignees

No one assigned

    Labels

    Has WorkaroundThis PR or Issue has a work around detailed within it.Resolution: Needs InvestigationThis PR or Issue should be investigated from the Stencil team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions