Skip to content

Commit

Permalink
fix(angular): create angular delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Mar 13, 2018
1 parent f398b3a commit 3b5f758
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 9 deletions.
8 changes: 5 additions & 3 deletions angular/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ import { ToastController } from './providers/toast-controller';
VirtualHeader,
VirtualFooter
],
providers: [
AngularDelegate,
ModalController,
PopoverController,
],
imports: [
CommonModule,
],
Expand All @@ -81,9 +86,6 @@ export class IonicAngularModule {
return {
ngModule: IonicAngularModule,
providers: [
ModalController,
PopoverController,
AngularDelegate,
AlertController,
ActionSheetController,
Events,
Expand Down
14 changes: 13 additions & 1 deletion angular/src/providers/angular-delegate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ import { FrameworkDelegate } from '@ionic/core';


@Injectable()
export class AngularDelegate implements FrameworkDelegate {
export class AngularDelegate {

constructor(
private appRef: ApplicationRef
) {}

create(cfr: ComponentFactoryResolver, injector: Injector) {
return new AngularFrameworkDelegate(cfr, injector, this.appRef);
}
}


export class AngularFrameworkDelegate implements FrameworkDelegate {

private elRefMap = new WeakMap<HTMLElement, any>();

Expand Down
6 changes: 4 additions & 2 deletions angular/src/providers/modal-controller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Injectable } from '@angular/core';
import { ComponentFactoryResolver, Injectable, Injector } from '@angular/core';
import { ModalOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
import { AngularDelegate } from './angular-delegate';

@Injectable()
export class ModalController extends OverlayBaseController<ModalOptions, HTMLIonModalElement> {
constructor(
private cfr: ComponentFactoryResolver,
private injector: Injector,
private angularDelegate: AngularDelegate,
) {
super('ion-modal-controller');
Expand All @@ -14,7 +16,7 @@ export class ModalController extends OverlayBaseController<ModalOptions, HTMLIon
create(opts?: ModalOptions): Promise<HTMLIonModalElement> {
return super.create({
...opts,
delegate: this.angularDelegate
delegate: this.angularDelegate.create(this.cfr, this.injector)
});
}
}
16 changes: 14 additions & 2 deletions angular/src/providers/popover-controller.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
import { Injectable } from '@angular/core';
import { ComponentFactoryResolver, Injectable, Injector } from '@angular/core';
import { PopoverOptions } from '@ionic/core';
import { OverlayBaseController } from '../util/overlay';
import { AngularDelegate } from './angular-delegate';

@Injectable()
export class PopoverController extends OverlayBaseController<PopoverOptions, HTMLIonPopoverElement> {
constructor() {
constructor(
private cfr: ComponentFactoryResolver,
private injector: Injector,
private angularDelegate: AngularDelegate,
) {
super('ion-popover-controller');
}

create(opts?: PopoverOptions): Promise<HTMLIonPopoverElement> {
return super.create({
...opts,
delegate: this.angularDelegate.create(this.cfr, this.injector)
});
}
}
2 changes: 1 addition & 1 deletion angular/src/providers/toast-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { OverlayBaseController } from '../util/overlay';
@Injectable()
export class ToastController extends OverlayBaseController<ToastOptions, HTMLIonToastElement> {
constructor() {
super('ion-popover-controller');
super('ion-toast-controller');
}
}

0 comments on commit 3b5f758

Please sign in to comment.