chore(angular): have demo use

This commit is contained in:
Dan Bucholtz
2017-11-22 16:09:19 -06:00
parent 45cbe4a650
commit d13c964832
4 changed files with 77 additions and 136 deletions

View File

@ -1,6 +1,6 @@
import { Component } from '@angular/core';
// import { AlertController } from '@ionic/angular';
import { AlertController } from '@ionic/angular';
@Component({
selector: 'app-alert-page',
@ -21,19 +21,33 @@ import { Component } from '@angular/core';
})
export class AlertPageComponent {
constructor(/*private alertController: AlertController*/) {
constructor(private alertController: AlertController) {
}
clickMe() {
/*const alert = this.alertController.create({
const alert = this.alertController.create({
title: 'ohhhh snap',
message: 'Gretting from an ng cli app',
message: 'Ive been injected via Angular keeping the old api',
buttons: [
{
text: 'Cancel',
role: 'Cancel',
handler: () => {
console.log('cancel');
}
},
{
text: 'Okay',
role: 'Okay',
handler: () => {
console.log('okay');
}
}
]
});
alert.present();
*/
alert('kaboom');
}
}

View File

@ -1,64 +0,0 @@
import { Injectable } from '@angular/core';
import { AlertOptions } from '@ionic/core';
import { ensureElementInBody, hydrateElement } from '../util/util';
let alertId = 0;
@Injectable()
export class AlertController {
create(opts?: AlertOptions): any {
return getAlertProxy(opts);
}
}
export function getAlertProxy(opts: AlertOptions) {
return {
id: alertId++,
state: PRESENTING,
opts: opts,
present: function() {
return present(this);
},
dismiss: function() {
return dismiss(this);
}
};
}
export function present(alertProxy: AlertProxyInternal): Promise<void> {
return loadOverlay(alertProxy.opts).then((alertElement: HTMLIonAlertElement) => {
if (alertProxy.state === PRESENTING) {
return alertElement.present();
}
});
}
export function dismiss(alertProxy: AlertProxyInternal): Promise<void> {
return loadOverlay(alertProxy.opts).then((alertElement: HTMLIonAlertElement) => {
if (alertProxy.state === DISMISSING) {
return alertElement.dismiss();
}
});
}
export function loadOverlay(opts: AlertOptions) {
const element = ensureElementInBody('ion-alert-controller') as HTMLIonAlertControllerElement;
return hydrateElement(element).then(() => {
return element.create(opts);
});
}
export interface AlertProxy {
present(): Promise<void>;
dismiss(): Promise<void>;
}
export interface AlertProxyInternal extends AlertProxy {
id: number;
opts: AlertOptions;
state: number;
}
export const PRESENTING = 1;
export const DISMISSING = 2;

View File

@ -1,17 +0,0 @@
export function hydrateElement(element: any) {
return element.componentOnReady();
}
export function getElement(elementName: string) {
return document.querySelector(elementName);
}
export function ensureElementInBody(elementName: string) {
let element = getElement(elementName);
if (!element) {
element = document.createElement(elementName);
document.body.appendChild(element);
}
return element;
}