mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-16 01:52:19 +08:00
feat(angular): strongly type Ionic lifecycle hooks (#18044)
closes #18043
This commit is contained in:

committed by
GitHub

parent
29d208de88
commit
53fc8e37c8
@ -36,6 +36,9 @@ export { GestureController } from './providers/gesture-controller';
|
|||||||
// ROUTER STRATEGY
|
// ROUTER STRATEGY
|
||||||
export { IonicRouteStrategy } from './util/ionic-router-reuse-strategy';
|
export { IonicRouteStrategy } from './util/ionic-router-reuse-strategy';
|
||||||
|
|
||||||
|
// TYPES
|
||||||
|
export * from './types/ionic-lifecycle-hooks';
|
||||||
|
|
||||||
// PACKAGE MODULE
|
// PACKAGE MODULE
|
||||||
export { IonicModule } from './ionic-module';
|
export { IonicModule } from './ionic-module';
|
||||||
|
|
||||||
|
31
angular/src/types/ionic-lifecycle-hooks.ts
Normal file
31
angular/src/types/ionic-lifecycle-hooks.ts
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/**
|
||||||
|
* https://ionicframework.com/docs/api/router-outlet#life-cycle-hooks
|
||||||
|
*/
|
||||||
|
|
||||||
|
export interface ViewWillEnter {
|
||||||
|
/**
|
||||||
|
* Fired when the component routing to is about to animate into view.
|
||||||
|
*/
|
||||||
|
ionViewWillEnter(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ViewDidEnter {
|
||||||
|
/**
|
||||||
|
* Fired when the component routing to has finished animating.
|
||||||
|
*/
|
||||||
|
ionViewDidEnter(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ViewWillLeave {
|
||||||
|
/**
|
||||||
|
* Fired when the component routing from is about to animate.
|
||||||
|
*/
|
||||||
|
ionViewWillLeave(): void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ViewDidLeave {
|
||||||
|
/**
|
||||||
|
* Fired when the component routing to has finished animating.
|
||||||
|
*/
|
||||||
|
ionViewDidLeave(): void;
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
import { Component, Input, NgZone, OnInit, Optional } from '@angular/core';
|
import { Component, Input, NgZone, OnInit, Optional } from '@angular/core';
|
||||||
import { ModalController, NavParams, IonNav } from '@ionic/angular';
|
import { ModalController, NavParams, IonNav, ViewWillLeave, ViewDidEnter, ViewDidLeave } from '@ionic/angular';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-modal-example',
|
selector: 'app-modal-example',
|
||||||
templateUrl: './modal-example.component.html',
|
templateUrl: './modal-example.component.html',
|
||||||
})
|
})
|
||||||
export class ModalExampleComponent implements OnInit {
|
export class ModalExampleComponent implements OnInit, ViewWillLeave, ViewDidEnter, ViewWillLeave, ViewDidLeave {
|
||||||
|
|
||||||
@Input() value: string;
|
@Input() value: string;
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { Component, OnInit, NgZone } from '@angular/core';
|
import { Component, OnInit, NgZone } from '@angular/core';
|
||||||
import { IonRouterOutlet } from '@ionic/angular';
|
import { IonRouterOutlet, ViewDidEnter, ViewDidLeave, ViewWillLeave } from '@ionic/angular';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-router-link-page',
|
selector: 'app-router-link-page',
|
||||||
templateUrl: './router-link-page.component.html',
|
templateUrl: './router-link-page.component.html',
|
||||||
})
|
})
|
||||||
export class RouterLinkPageComponent implements OnInit {
|
export class RouterLinkPageComponent implements OnInit, ViewWillLeave, ViewDidEnter, ViewWillLeave, ViewDidLeave {
|
||||||
|
|
||||||
onInit = 0;
|
onInit = 0;
|
||||||
willEnter = 0;
|
willEnter = 0;
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
import { Component, NgZone, OnInit } from '@angular/core';
|
import { Component, NgZone, OnInit } from '@angular/core';
|
||||||
import { NavController } from '@ionic/angular';
|
import { NavController, ViewDidEnter, ViewDidLeave, ViewWillEnter, ViewWillLeave } from '@ionic/angular';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-router-link',
|
selector: 'app-router-link',
|
||||||
templateUrl: './router-link.component.html',
|
templateUrl: './router-link.component.html',
|
||||||
})
|
})
|
||||||
export class RouterLinkComponent implements OnInit {
|
export class RouterLinkComponent implements OnInit, ViewWillEnter, ViewDidEnter, ViewWillLeave, ViewDidLeave {
|
||||||
|
|
||||||
onInit = 0;
|
onInit = 0;
|
||||||
willEnter = 0;
|
willEnter = 0;
|
||||||
|
@ -1,11 +1,12 @@
|
|||||||
import { Component, NgZone, OnInit } from '@angular/core';
|
import { Component, NgZone, OnInit } from '@angular/core';
|
||||||
import { ActivatedRoute } from '@angular/router';
|
import { ActivatedRoute } from '@angular/router';
|
||||||
|
import { ViewDidEnter, ViewDidLeave, ViewWillEnter, ViewWillLeave } from '@ionic/angular';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-virtual-scroll-detail',
|
selector: 'app-virtual-scroll-detail',
|
||||||
templateUrl: './virtual-scroll-detail.component.html',
|
templateUrl: './virtual-scroll-detail.component.html',
|
||||||
})
|
})
|
||||||
export class VirtualScrollDetailComponent implements OnInit {
|
export class VirtualScrollDetailComponent implements OnInit, ViewWillEnter, ViewDidEnter, ViewWillLeave, ViewDidLeave {
|
||||||
|
|
||||||
onInit = 0;
|
onInit = 0;
|
||||||
willEnter = 0;
|
willEnter = 0;
|
||||||
|
@ -12,12 +12,12 @@ Although router outlet has methods for navigating around, it's recommended to us
|
|||||||
Routes rendered in a Router Outlet have access to specific Ionic events that are wired up to animations
|
Routes rendered in a Router Outlet have access to specific Ionic events that are wired up to animations
|
||||||
|
|
||||||
|
|
||||||
| Event Name | Trigger |
|
| Event Name | Trigger |
|
||||||
|--------------------|------------------------------------------------------------------|
|
|--------------------|--------------------------------------------------------------------|
|
||||||
| `ionViewWillEnter` | Fired when the component being routed to is about to animate in. |
|
| `ionViewWillEnter` | Fired when the component routing to is about to animate into view. |
|
||||||
| `ionViewDidEnter` | Fired when the component being routed to has animated in. |
|
| `ionViewDidEnter` | Fired when the component routing to has finished animating. |
|
||||||
| `ionViewWillLeave` | Fired when the component being routed from is about to animate. |
|
| `ionViewWillLeave` | Fired when the component routing from is about to animate. |
|
||||||
| `ionViewDidLeave` | Fired when the component being routed from has animated. |
|
| `ionViewDidLeave` | Fired when the component routing to has finished animating. |
|
||||||
|
|
||||||
|
|
||||||
These event tie into Ionic's animation system and can be used to coordinate parts of your app when a Components is done with it's animation. These events are not a replacement for Angular's own event system, but an addition.
|
These event tie into Ionic's animation system and can be used to coordinate parts of your app when a Components is done with it's animation. These events are not a replacement for Angular's own event system, but an addition.
|
||||||
|
Reference in New Issue
Block a user