Skip to content

docs-bug(MatDialog): Document standalone import #26124

Open
@robert-king

Description

@robert-king

Documentation Feedback

TLDR; would be nice to document how to provide dialog and snackbar for standalone components.
I don't want to provide MatDialogModule for every standalone component that uses a dialog.

I guess I could add it to main.ts. I have a convenience service that does alert(), confirm(), error() dialogs and hides the MatDialogModule from simple components. I don't have a great way of providing MatDialogModule for this convenience service.

in the docs it says:

import {MatDialogModule} from '@angular/material/dialog';

now that i'm using standalone components,
is it recommend to use:
importProvidersFrom(MatDialogModule),
in main.ts

e.g.


bootstrapApplication(AppComponent, {
  providers: [
    // https://this-is-angular.github.io/angular-guides/docs/standalone-apis/configuring-the-router-using-standalone-features
    provideRouter(
      routes,
      withDebugTracing()),
    importProvidersFrom(HttpClientModule),
    importProvidersFrom(MatDialogModule),
    provideAnimations(),
  ]
}).catch(err => console.error(err));

I guess it wouldn't make sense to provide MatDialogModule to the convenience service separately to how I provide it to some standalone components, as then perhaps the app would have inconsistent dialogs, so in main.ts makes sense, just feels disorganised.

Affected documentation page

https://material.angular.io/components/dialog/api

p.s

also worth mentioning, fyi, sometimes we have to explicitly import our components to avoid errors, but we don't have any entrypoints or anything:


async serviceMethodThatOpensDialog(
  ) {
    const { SparkplugbDatapointBulkCreateComponent } = await import('../datapoint-sparkplugb/sparkplugb-datapoint-bulk-create/sparkplugb-datapoint-bulk-create.component'
    )
    return this.dialog.open(SparkplugbDatapointBulkCreateComponent, {
      data: {
      }
    })
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4A relatively minor issue that is not relevant to core functionsarea: docsRelated to the documentationarea: material/dialog

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions