Skip to content

Commit f8c71aa

Browse files
committed
refactor(angular): improving code example
1 parent fb6d127 commit f8c71aa

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

docs/angular/injection-tokens.md

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,6 @@ sidebar_label: Injection Tokens
1212
</head>
1313

1414
Ionic provides Angular injection tokens that allow you to access Ionic elements through Angular's dependency injection system. This provides a more Angular-idiomatic way to interact with Ionic components programmatically.
15-
16-
## IonModalToken
17-
18-
The `IonModalToken` injection token allows you to inject a reference to the current modal element directly into your Angular components. This is particularly useful when you need to programmatically control modal behavior, listen to modal events, or access modal properties.
19-
20-
Starting in `@ionic/angular` v8.7.0, you can use this injection token to streamline modal interactions in your Angular applications.
21-
2215
## Benefits
2316

2417
Using injection tokens provides several advantages:
@@ -28,6 +21,12 @@ Using injection tokens provides several advantages:
2821
- **Simplified Code**: Eliminates the need for `ViewChild` queries or manual element references
2922
- **Better Testing**: Easier to mock and test components that use injection tokens
3023

24+
## IonModalToken
25+
26+
The `IonModalToken` injection token allows you to inject a reference to the current modal element directly into your Angular components. This is particularly useful when you need to programmatically control modal behavior, listen to modal events, or access modal properties.
27+
28+
Starting in `@ionic/angular` v8.7.0, you can use this injection token to streamline modal interactions in your Angular applications.
29+
3130
### Basic Usage
3231

3332
To use the `IonModalToken`, inject it into your component's constructor:
@@ -150,7 +149,7 @@ When opening a modal that uses the injection token, you can pass the component d
150149
```tsx
151150
import { Component, inject } from '@angular/core';
152151
import { IonContent, IonButton, ModalController } from '@ionic/angular/standalone';
153-
import { ModalContentComponent } from './modal-content.component';
152+
import { ModalComponent } from './modal.component';
154153

155154
@Component({
156155
selector: 'app-home',
@@ -164,14 +163,14 @@ export class HomePage {
164163
private modalController = inject(ModalController);
165164

166165
async openModal() {
167-
const modal = await this.modalController.create({
168-
component: ModalContentComponent,
166+
const myModal = await this.modalController.create({
167+
component: ModalComponent,
169168
componentProps: {
170169
// Any props you want to pass to the modal content
171170
},
172171
});
173172

174-
await modal.present();
173+
await myModal.present();
175174
}
176175
}
177176
```

0 commit comments

Comments
 (0)