Skip to content

Commit 43a52dd

Browse files
docs: use inject() and bootstrapApplication in dialog, snack-bar, and bottom-sheet docs (#32839)
1 parent 267b658 commit 43a52dd

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

src/cdk/dialog/dialog.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ in which they are contained. When closing, an optional result value can be provi
5050
value is forwarded as the result of the `closed` Observable.
5151

5252
```ts
53+
import {inject} from '@angular/core';
54+
5355
@Component({/* ... */})
5456
export class YourDialog {
55-
constructor(public dialogRef: DialogRef<string>) {}
57+
dialogRef = inject<DialogRef<string>>(DialogRef);
5658

5759
closeDialog() {
5860
this.dialogRef.close('Pizza!');
@@ -117,14 +119,14 @@ class MyDialogContainer extends CdkDialogContainer {}
117119

118120
### Specifying global configuration defaults
119121
Default dialog options can be specified by providing an instance of `DialogConfig` for
120-
`DEFAULT_DIALOG_CONFIG` in your application's root module.
122+
`DEFAULT_DIALOG_CONFIG` in your app config.
121123

122124
```ts
123-
@NgModule({
125+
bootstrapApplication(MyApp, {
124126
providers: [
125127
{provide: DEFAULT_DIALOG_CONFIG, useValue: {hasBackdrop: false}}
126128
]
127-
})
129+
});
128130
```
129131

130132
### Sharing data with the Dialog component.
@@ -139,15 +141,15 @@ const dialogRef = dialog.open(YourDialog, {
139141
Access the data in your dialog component with the `DIALOG_DATA` injection token:
140142

141143
```ts
142-
import {Component, Inject} from '@angular/core';
144+
import {Component, inject} from '@angular/core';
143145
import {DIALOG_DATA} from '@angular/cdk/dialog';
144146

145147
@Component({
146148
selector: 'your-dialog',
147149
template: 'passed in {{ data.name }}',
148150
})
149151
export class YourDialog {
150-
constructor(@Inject(DIALOG_DATA) public data: {name: string}) { }
152+
data = inject<{name: string}>(DIALOG_DATA);
151153
}
152154
```
153155

src/material/bottom-sheet/bottom-sheet.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ const bottomSheetRef = bottomSheet.open(HobbitSheet, {
3737
Afterwards you can access the injected data using the `MAT_BOTTOM_SHEET_DATA` injection token:
3838

3939
```ts
40-
import {Component, Inject} from '@angular/core';
41-
import {MAT_BOTTOM_SHEET_DATA} from '../bottom-sheet';
40+
import {Component, inject} from '@angular/core';
41+
import {MAT_BOTTOM_SHEET_DATA} from '@angular/material/bottom-sheet';
4242

4343
@Component({
4444
selector: 'hobbit-sheet',
4545
template: 'passed in {{ data.names }}',
4646
})
4747
export class HobbitSheet {
48-
constructor(@Inject(MAT_BOTTOM_SHEET_DATA) public data: {names: string[]}) { }
48+
data = inject<{names: string[]}>(MAT_BOTTOM_SHEET_DATA);
4949
}
5050
```
5151

@@ -54,11 +54,11 @@ Default bottom sheet options can be specified by providing an instance of `MatBo
5454
for `MAT_BOTTOM_SHEET_DEFAULT_OPTIONS` in your application's root module.
5555

5656
```ts
57-
@NgModule({
57+
bootstrapApplication(MyApp, {
5858
providers: [
5959
{provide: MAT_BOTTOM_SHEET_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
6060
]
61-
})
61+
});
6262
```
6363

6464

src/material/dialog/dialog.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ in which they are contained. When closing, an optional result value can be provi
2929
value is forwarded as the result of the `afterClosed` Observable.
3030

3131
```ts
32+
import {inject} from '@angular/core';
33+
3234
@Component({/* ... */})
3335
export class YourDialog {
34-
constructor(public dialogRef: MatDialogRef<YourDialog>) { }
36+
dialogRef = inject(MatDialogRef);
3537

3638
closeDialog() {
3739
this.dialogRef.close('Pizza!');
@@ -41,14 +43,14 @@ export class YourDialog {
4143

4244
### Specifying global configuration defaults
4345
Default dialog options can be specified by providing an instance of `MatDialogConfig` for
44-
MAT_DIALOG_DEFAULT_OPTIONS in your application's root module.
46+
`MAT_DIALOG_DEFAULT_OPTIONS` in your app config.
4547

4648
```ts
47-
@NgModule({
49+
bootstrapApplication(MyApp, {
4850
providers: [
4951
{provide: MAT_DIALOG_DEFAULT_OPTIONS, useValue: {hasBackdrop: false}}
5052
]
51-
})
53+
});
5254
```
5355

5456
### Sharing data with the Dialog component.
@@ -64,15 +66,15 @@ let dialogRef = dialog.open(YourDialog, {
6466
To access the data in your dialog component, you have to use the MAT_DIALOG_DATA injection token:
6567

6668
```ts
67-
import {Component, Inject} from '@angular/core';
68-
import {MAT_DIALOG_DATA} from '../dialog';
69+
import {Component, inject} from '@angular/core';
70+
import {MAT_DIALOG_DATA} from '@angular/material/dialog';
6971

7072
@Component({
7173
selector: 'your-dialog',
7274
template: 'passed in {{ data.name }}',
7375
})
7476
export class YourDialog {
75-
constructor(@Inject(MAT_DIALOG_DATA) public data: {name: string}) { }
77+
data = inject<{name: string}>(MAT_DIALOG_DATA);
7678
}
7779
```
7880

src/material/snack-bar/snack-bar.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ snackBar.openFromComponent(MessageArchivedComponent, {
6161
To access the data in your component, you have to use the `MAT_SNACK_BAR_DATA` injection token:
6262

6363
```ts
64-
import {Component, Inject} from '@angular/core';
65-
import {MAT_SNACK_BAR_DATA} from '../snack-bar';
64+
import {Component, inject} from '@angular/core';
65+
import {MAT_SNACK_BAR_DATA} from '@angular/material/snack-bar';
6666

6767
@Component({
6868
selector: 'your-snackbar',
6969
template: 'passed in {{ data }}',
7070
})
7171
export class MessageArchivedComponent {
72-
constructor(@Inject(MAT_SNACK_BAR_DATA) public data: string) { }
72+
data = inject<string>(MAT_SNACK_BAR_DATA);
7373
}
7474
```
7575

@@ -91,11 +91,11 @@ If you want to override the default snack bar options, you can do so using the
9191
`MAT_SNACK_BAR_DEFAULT_OPTIONS` injection token.
9292

9393
```ts
94-
@NgModule({
94+
bootstrapApplication(MyApp, {
9595
providers: [
9696
{provide: MAT_SNACK_BAR_DEFAULT_OPTIONS, useValue: {duration: 2500}}
9797
]
98-
})
98+
});
9999
```
100100

101101
### Accessibility

0 commit comments

Comments
 (0)