1

I am trying to use mat-dialog in my angular custom element. I works fine when in the angular app but can't seem to bundle the material theme while building to custom element.

When i inspect the code outside of angular app, no style is attached to any of the cdk class. Everything seem to work fine when running in the angular server. How do i include the needed css with the custom element?

My app.module file

@NgModule({
  [ ...
   MatFormFieldModule,
   MatIconModule,
   MatSelectModule,
   MatInputModule,
   MatDialogModule,
  ...
 ],
  providers: [ConnectBackendService],
  entryComponents: [AppComponent, PopupComponent]
})
export class AppModule {
  constructor(private injector: Injector) {
    const el = createCustomElement(AppComponent, { injector });
    customElements.define('my-element', <Function>el);
  }

 ngDoBootstrap() {}
}

and my styles.css file

@import "~@angular/material/prebuilt-themes/indigo-pink.css";

My dialog should have absolute positioning, should be aligned to the center of the window and should have a backdrop. Currently, none of these applies to the dialog box

cozmik05
  • 477
  • 5
  • 13
  • can you add a slackblitz sample? – Akhi Akl Dec 28 '18 at 05:51
  • found the cause. Turns out **style.css** is not part of the build with element, it worked when i referenced the one in the **dist** folder manually. Does anyone know how I can concat **style.js** with my custom element js file? Or is it a bad idea. Thanks – cozmik05 Dec 28 '18 at 07:11
  • Fixed it by going to **angular.json** file, changed _extractCss_ property to false and added **styles.js** to build files – cozmik05 Dec 28 '18 at 07:40

2 Answers2

0

I had the same issue and i reported it to Google on their GitHub page for Angular components. It is now tagged as "Low-priority issue that needs to be resolved" by Google.

https://github.com/angular/components/issues/15968

Just letting you and anyone else who sees this thread know so that they can find a possible future fix in my github post when/if Google fixes this issue.

Turbolego
  • 9
  • 1
  • 7
0

Fixed it by going to angular.json file, changed extractCss property to false and added styles.js to build files

cozmik05
  • 477
  • 5
  • 13