-
Notifications
You must be signed in to change notification settings - Fork 13.3k
feat(angular): add standalone provideIonicAngular #27996
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
07b8d2f
feat(angular): standalone has IonicRouteStrategy
liamdebeasi 831ebab
feat(angular): standalone exports providers
liamdebeasi 4125272
chore: remove delegate
liamdebeasi 5f551b1
refactor: component binding exists in common
liamdebeasi 72886f0
lint
liamdebeasi 062043a
feat(angular): add provideIonicAngular
liamdebeasi bbd69c0
feat(angular): standalone has route strategy
liamdebeasi 2b2a96a
test(angular): use provideIonicAngular
liamdebeasi 283d42b
fix: lazy loaded components are bootstrapped correctly
liamdebeasi cedcc13
whitespace
liamdebeasi 7fc0bc7
test(angular): add providers test
liamdebeasi bfb7bce
lint
liamdebeasi f060736
refactor: use component input provider from common
liamdebeasi ebc1625
sync
liamdebeasi aacd70b
test: angular standalone runs on angular 14
liamdebeasi a42f76a
Update ionic-angular.ts
liamdebeasi 7e9bd57
remove invalid todos
liamdebeasi 98e3110
provider AngularDelegate on root
liamdebeasi 4969ce3
add angular delegate on root
liamdebeasi fbd280d
fix(angular): modal and popover controllers are providers
liamdebeasi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/angular/standalone/src/providers/ionic-angular.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { DOCUMENT } from '@angular/common'; | ||
| import { APP_INITIALIZER } from '@angular/core'; | ||
| import type { Provider } from '@angular/core'; | ||
| import { | ||
| AngularDelegate, | ||
| ConfigToken, | ||
| ModalController, | ||
| PopoverController, | ||
| provideComponentInputBinding, | ||
| } from '@ionic/angular/common'; | ||
| import { initialize } from '@ionic/core/components'; | ||
| import type { IonicConfig } from '@ionic/core/components'; | ||
|
|
||
| export const provideIonicAngular = (config?: IonicConfig): Provider[] => { | ||
| /** | ||
| * TODO FW-4967 | ||
| * Use makeEnvironmentProviders once Angular 14 support is dropped. | ||
| * This prevents provideIonicAngular from being accidentally referenced in an @Component. | ||
| */ | ||
| return [ | ||
| { | ||
| provide: ConfigToken, | ||
| useValue: config, | ||
| }, | ||
| { | ||
| provide: APP_INITIALIZER, | ||
| useFactory: initializeIonicAngular, | ||
| multi: true, | ||
| deps: [ConfigToken, DOCUMENT], | ||
| }, | ||
| provideComponentInputBinding(), | ||
| AngularDelegate, | ||
| ModalController, | ||
| PopoverController, | ||
| ]; | ||
| }; | ||
|
|
||
| const initializeIonicAngular = (config: IonicConfig, doc: Document) => { | ||
| return () => { | ||
| /** | ||
| * By default Ionic Framework hides elements that | ||
| * are not hydrated, but in the CE build there is no | ||
| * hydration. | ||
| * TODO FW-2797: Remove when all integrations have been | ||
| * migrated to CE build. | ||
| */ | ||
| doc.documentElement.classList.add('ion-ce'); | ||
|
|
||
| initialize(config); | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import { importProvidersFrom } from '@angular/core'; | ||
| import { bootstrapApplication } from '@angular/platform-browser'; | ||
| import { RouteReuseStrategy } from '@angular/router'; | ||
| import { provideIonicAngular, IonicRouteStrategy } from '@ionic/angular/standalone'; | ||
|
|
||
| import { AppComponentStandalone } from './app/app-standalone.component'; | ||
| import { AppRoutingModule } from './app/app-routing.module'; | ||
|
|
||
| import { routes } from './app/app.routes'; | ||
|
|
||
| export const bootstrapStandalone = () => { | ||
| bootstrapApplication(AppComponentStandalone, { | ||
| providers: [ | ||
| { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, | ||
| /** | ||
| * provideRouter is not available in Angular 14, so | ||
| * we fallback to using AppRoutingModule | ||
| */ | ||
| importProvidersFrom(AppRoutingModule), | ||
| provideIonicAngular({ keyboardHeight: 12345 }) | ||
| ], | ||
| }); | ||
| } |
17 changes: 17 additions & 0 deletions
17
packages/angular/test/base/e2e/src/standalone/overlay-controllers.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| describe('Overlay Controllers', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/standalone/overlay-controllers'); | ||
| }) | ||
|
|
||
| it('should present a modal', () => { | ||
| cy.get('button#open-modal').click(); | ||
|
|
||
| cy.get('ion-modal app-dialog-content').should('be.visible'); | ||
| }); | ||
|
|
||
| it('should present a popover', () => { | ||
| cy.get('button#open-popover').click(); | ||
|
|
||
| cy.get('ion-popover app-dialog-content').should('be.visible'); | ||
| }); | ||
| }) |
11 changes: 11 additions & 0 deletions
11
packages/angular/test/base/e2e/src/standalone/providers.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| describe('Providers', () => { | ||
| beforeEach(() => { | ||
| cy.visit('/standalone/providers'); | ||
| }) | ||
|
|
||
| it('provideIonicAngular should initialize Ionic and set config correctly', () => { | ||
| cy.ionPageVisible('app-providers'); | ||
|
|
||
| cy.get('#keyboard-height').should('have.text', '12345'); | ||
| }); | ||
| }) |
11 changes: 11 additions & 0 deletions
11
packages/angular/test/base/src/app/app-standalone.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { RouterModule } from '@angular/router'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-root', | ||
| templateUrl: './app.component.html', | ||
| standalone: true, | ||
| imports: [RouterModule] | ||
| }) | ||
| export class AppComponentStandalone { | ||
| } |
9 changes: 0 additions & 9 deletions
9
packages/angular/test/base/src/app/standalone/app-standalone/app.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
...gular/test/base/src/app/standalone/overlay-controllers/overlay-controllers.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <div> | ||
| <button id="open-modal" (click)="openModal()">Open Modal</button> | ||
| <button id="open-popover" (click)="openPopover($event)">Open Popover</button> | ||
| </div> |
36 changes: 36 additions & 0 deletions
36
...angular/test/base/src/app/standalone/overlay-controllers/overlay-controllers.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { ModalController, PopoverController } from '@ionic/angular/standalone'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-overlay-controllers', | ||
| templateUrl: './overlay-controllers.component.html', | ||
| standalone: true, | ||
| }) | ||
| export class OverlayControllersComponent { | ||
| constructor(private modalCtrl: ModalController, private popoverCtrl: PopoverController) {} | ||
|
|
||
| async openModal() { | ||
| const modal = await this.modalCtrl.create({ | ||
| component: DialogComponent | ||
| }); | ||
|
|
||
| await modal.present(); | ||
| } | ||
|
|
||
| async openPopover(ev: MouseEvent) { | ||
| const popover = await this.popoverCtrl.create({ | ||
| component: DialogComponent, | ||
| event: ev | ||
| }); | ||
|
|
||
| await popover.present(); | ||
| } | ||
| } | ||
|
|
||
| @Component({ | ||
| selector: 'app-dialog-content', | ||
| template: '<div class="ion-padding">Dialog Content</div>', | ||
| standalone: true, | ||
| }) | ||
| class DialogComponent { | ||
| } |
4 changes: 4 additions & 0 deletions
4
packages/angular/test/base/src/app/standalone/providers/providers.component.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| <ul> | ||
| <li>Keyboard Height: <span id="keyboard-height">{{ keyboardHeight }}</span></li> | ||
| </ul> | ||
|
|
15 changes: 15 additions & 0 deletions
15
packages/angular/test/base/src/app/standalone/providers/providers.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Component } from '@angular/core'; | ||
| import { Config } from '@ionic/angular/standalone'; | ||
|
|
||
| @Component({ | ||
| selector: 'app-providers', | ||
| templateUrl: './providers.component.html', | ||
| standalone: true, | ||
| }) | ||
| export class ProvidersComponent { | ||
| keyboardHeight?: number; | ||
|
|
||
| constructor(private config: Config) { | ||
| this.keyboardHeight = config.get('keyboardHeight'); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { bootstrapApplication } from '@angular/platform-browser'; | ||
| import { RouteReuseStrategy, provideRouter } from '@angular/router'; | ||
| import { provideIonicAngular, IonicRouteStrategy } from '@ionic/angular/standalone'; | ||
|
|
||
| import { AppComponentStandalone } from './app/app-standalone.component'; | ||
|
|
||
| import { routes } from './app/app.routes'; | ||
|
|
||
| export const bootstrapStandalone = () => { | ||
| bootstrapApplication(AppComponentStandalone, { | ||
| providers: [ | ||
| { provide: RouteReuseStrategy, useClass: IonicRouteStrategy }, | ||
| provideRouter(routes), | ||
| provideIonicAngular({ keyboardHeight: 12345 }) | ||
| ], | ||
| }); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried copy and pasting the implementation of
makeEnvironmentProviders. This worked on ng15+ but broke on ng14. I'm not aware of a way to do feature detection here, so I opted to go without it for now.