mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-11-08 23:58:13 +08:00
chore(angular): have demo use
This commit is contained in:
@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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;
|
||||
@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user