mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-07 23:16:52 +08:00
feat(modal): add IonModalToken for injecting modal elements in Angular components (#30474)
Issue number: resolves #internal --------- <!-- Please do not submit updates to dependencies unless it fixes an issue. --> <!-- Please try to limit your pull request to one type (bugfix, feature, etc). Submit multiple pull requests if needed. --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> Currently, we provide no injection access to angular modals, which makes it difficult to connect to their events normally. ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> This is an attempt to allow easier programmatic access to the internals of injected modals. ## Does this introduce a breaking change? - [ ] Yes - [X] No <!-- If this introduces a breaking change: 1. Describe the impact and migration path for existing applications below. 2. Update the BREAKING.md file with the breaking change. 3. Add "BREAKING CHANGE: [...]" to the commit description when merging. See https://github.com/ionic-team/ionic-framework/blob/main/docs/CONTRIBUTING.md#footer for more information. --> ## Other information <!-- Any other information that is important to this PR such as screenshots of how the component looks before and after the change. --> Dev build: `8.6.2-dev.11749830167.1460aa73`
This commit is contained in:
@ -1,34 +1,34 @@
|
||||
export { MenuController } from './providers/menu-controller';
|
||||
export { DomController } from './providers/dom-controller';
|
||||
export { MenuController } from './providers/menu-controller';
|
||||
export { NavController } from './providers/nav-controller';
|
||||
|
||||
export { Config, ConfigToken } from './providers/config';
|
||||
export { Platform } from './providers/platform';
|
||||
|
||||
export { bindLifecycleEvents, AngularDelegate } from './providers/angular-delegate';
|
||||
export { AngularDelegate, bindLifecycleEvents, IonModalToken } from './providers/angular-delegate';
|
||||
|
||||
export type { IonicWindow } from './types/interfaces';
|
||||
export type { ViewWillEnter, ViewWillLeave, ViewDidEnter, ViewDidLeave } from './types/ionic-lifecycle-hooks';
|
||||
export type { ViewDidEnter, ViewDidLeave, ViewWillEnter, ViewWillLeave } from './types/ionic-lifecycle-hooks';
|
||||
|
||||
export { NavParams } from './directives/navigation/nav-params';
|
||||
|
||||
export { IonPopover } from './overlays/popover';
|
||||
export { IonModal } from './overlays/modal';
|
||||
export { IonPopover } from './overlays/popover';
|
||||
|
||||
export { IonRouterOutlet, provideComponentInputBinding } from './directives/navigation/router-outlet';
|
||||
|
||||
export * from './directives/control-value-accessors';
|
||||
export { IonBackButton } from './directives/navigation/back-button';
|
||||
export { IonNav } from './directives/navigation/nav';
|
||||
export {
|
||||
RouterLinkDelegateDirective,
|
||||
RouterLinkWithHrefDelegateDirective,
|
||||
} from './directives/navigation/router-link-delegate';
|
||||
export { IonNav } from './directives/navigation/nav';
|
||||
export { IonTabs } from './directives/navigation/tabs';
|
||||
export * from './directives/control-value-accessors';
|
||||
|
||||
export { ProxyCmp } from './utils/proxy';
|
||||
|
||||
export { IonicRouteStrategy } from './utils/routing';
|
||||
export { OverlayBaseController } from './utils/overlay';
|
||||
export { IonicRouteStrategy } from './utils/routing';
|
||||
|
||||
export { raf } from './utils/util';
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
import {
|
||||
ApplicationRef,
|
||||
NgZone,
|
||||
Injectable,
|
||||
Injector,
|
||||
ComponentRef,
|
||||
createComponent,
|
||||
EnvironmentInjector,
|
||||
inject,
|
||||
createComponent,
|
||||
Injectable,
|
||||
InjectionToken,
|
||||
ComponentRef,
|
||||
Injector,
|
||||
NgZone,
|
||||
} from '@angular/core';
|
||||
import {
|
||||
FrameworkDelegate,
|
||||
@ -22,6 +22,9 @@ import { NavParams } from '../directives/navigation/nav-params';
|
||||
|
||||
import { ConfigToken } from './config';
|
||||
|
||||
// Token for injecting the modal element
|
||||
export const IonModalToken = new InjectionToken<HTMLIonModalElement>('IonModalToken');
|
||||
|
||||
// TODO(FW-2827): types
|
||||
|
||||
@Injectable()
|
||||
@ -142,8 +145,19 @@ export const attachView = (
|
||||
* The modern approach is to access the data directly
|
||||
* from the component's class instance.
|
||||
*/
|
||||
const providers = getProviders(params);
|
||||
|
||||
// If this is an ion-modal, provide the modal element as an injectable
|
||||
// so components inside the modal can inject it directly
|
||||
if (container.tagName.toLowerCase() === 'ion-modal') {
|
||||
providers.push({
|
||||
provide: IonModalToken,
|
||||
useValue: container,
|
||||
});
|
||||
}
|
||||
|
||||
const childInjector = Injector.create({
|
||||
providers: getProviders(params),
|
||||
providers,
|
||||
parent: injector,
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user