question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Angular Custom Elements & Angular 8 Material: MatDialog and MatMenu not working

See original GitHub issue

I am using angular custom elements to build an application in which a MatDialog is part of the custom element. I have a MatMenu in the host application as well. Problem is, when I open the mat-dialog on page load and then open the mat-menu, the mat-dialog is not working afterwards, otherwise if I open the menu first and then the mat-dialog, then the menu doesn’t work anymore.

You can find the stackblitz at : https://stackblitz.com/edit/angular-nr58ab-tbu38h

I have added the main.js code of the MatDialog application in the index.html itself. The main.js was generated after building the app with ngx-build-plus in prod mode with output-hashing none and single-bundle true.

The MatDialog app code is like this:

app.module.ts

import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";

import { NgModule, Injector } from "@angular/core";

import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import { createCustomElement } from "@angular/elements";

import { MatDialogModule, MatButtonModule } from "@angular/material";


@NgModule({
  declarations: [AppComponent],
  imports: [
    BrowserModule,
    AppRoutingModule,
    MatDialogModule,
    BrowserAnimationsModule,
    MatButtonModule
  ],
  providers: [],
  bootstrap: [AppComponent],
  entryComponents: [AppComponent]
})
export class AppModule {
  constructor(private injector: Injector) {
    const myCustomElement = createCustomElement(AppComponent, {
      injector: this.injector
    });
    customElements.define("app-test-data", myCustomElement);
  }
  ngDoBootstrap() {}
}

app.component.ts

import { Component, Input, TemplateRef } from "@angular/core";
import { MatDialog } from "@angular/material";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"]
})
export class AppComponent {
  constructor(private dialog: MatDialog) {}
  openModal(temp: TemplateRef<any>) {
    this.dialog.open(temp, { width: "100px", height: "100px" });
  }
}

and the app.component.html

<button mat-raised-button (click)="openModal(modal)">Open</button>

<ng-template #modal>
  <mat-dialog-content>
    Hello
  </mat-dialog-content>
</ng-template>

This is the app I have built and put inside the index.html of the app in the stackblitz.

I am stuck with this for some time now, I have tried running the dialog.open() inside NgZone.run() also, but no luck there either. Thanks.

Angular Setup:

Angular CLI: 8.3.21 Node: 13.6.0 OS: win32 x64 Angular: 8.2.14 … animations, common, compiler, compiler-cli, core, elements … forms, language-service, platform-browser … platform-browser-dynamic, router

Package Version

@angular-devkit/architect 0.803.21 @angular-devkit/build-angular 0.803.21 @angular-devkit/build-optimizer 0.803.21 @angular-devkit/build-webpack 0.803.21 @angular-devkit/core 8.3.21 @angular-devkit/schematics 8.3.21 @angular/cdk 8.2.3 @angular/cli 8.3.21 @angular/material 8.2.3 @ngtools/webpack 8.3.21 @schematics/angular 8.3.21 @schematics/update 0.803.21 rxjs 6.4.0 typescript 3.5.3 webpack 4.39.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yash0412commented, Jan 17, 2020

This seems like an issue with Angular Material that should be transferred to https://github.com/angular/components/issues?

FYI, Angular Components has an angular-elements label for issues that are specific to Angular Elements.

A number of Angular Element and Web Component fixes have gone into Angular Material 9.0.0-rc.7. Is it possible for your to try with the latest RCs of Angular, CLI, and Components?

Hey, thanks for the suggestion. I tried by updating @angular/cli and @angular/material to 9.0.0-rc.7, still no luck, the issue persists.

0reactions
angular-automatic-lock-bot[bot]commented, Jun 26, 2020

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular Custom Elements & Angular 8 Material: MatDialog ...
I have a MatMenu in the host application as well. Problem is, when I open the mat-dialog on page load and then open...
Read more >
MatDialog and MatMenu not working · Issue #18187 · angular ...
I am using angular custom elements to build an application in which a MatDialog is part of the custom element. I have a...
Read more >
Customizing component styles - Angular Material
While Angular Material does not support defining custom styles or CSS overrides on components' internal elements, you might choose to do this anyway....
Read more >
can't bind to 'mat-dialog-close' since it isn't a known property of ...
Hi, I'm trying to work with a tutorial about modal in angular 5 -> https://material.angular.io/components/dialog/overview and it's not working it giving me ...
Read more >
Custom Theme for Angular Material Components Series: Part 1
? --style will set our styling partner, i.e. scss , --skipTests will skip generating 'spec.ts' files for our project and --routing=false will not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found