Angular accomplishFirst of all, there is no need to say much about the implementation method. Using the hook function requires implementing the corresponding interface when defining it export class ListPage implements OnInit { constructor() {} ngOnInit() { // code here } } Calling order1.constructor The first thing to be executed is the constructor. When the constructor is executed, many variables such as @Input and @ViewChild do not exist. It is best to write related operations in ngOnInit. 2. ngOnChanges It is triggered when the binding value of the current component @Input/@Output changes. 3. ngOnInit Called after the first ngOnChanges is completed. It will only be executed once. 4. ngDoCheck Developer-defined change detection. 5. ngAfterContentInit Executed once when the component content is initialized 6. ngAfterContentChecked The content projected to the component is triggered after each ngDoCheck call. 7. ngAfterViewInit Executed once when the component and its subcomponent views are initialized 8. ngAfterViewChecked Fired after each ngDoCheck call on a component and its child views. 9. ngOnDestroy Called before the component is destroyed. Notice
IonicYou can click the link above to see the original document, and I will highlight the key points. The life cycle is shown in the figure. In addition to the life cycle provided by Angular, Ionic adds several events:
ionViewWillEnter is triggered after ngOnInit, and ionViewDidEnter is triggered after the transition effect of page switching ends
ionViewWillLeave is called first, and ionViewDidLeave is not called until the transition to the new page is successful (after the new page ionViewDidEnter is triggered). Components using ion-nav or ion-router-outlet should not use the OnPush change detection strategy, which will cause lifecycle hooks such as ngOnInit to fail to trigger. Additionally, asynchronously changing data may not render correctly. How does ionic handle the life cycle of a page?The routing outlet used by ionic is <ion-router-outlet />, which extends angular's <router-outlet /> and can provide a better experience on mobile devices. When jumping from one page to a new page, Ionic saves the old page in the DOM and hides it from view. This can maintain the status of the previous page, such as the scroll position and page data, so that when you return to the previous page from the new page, you do not need to reload it, and the page transition is smoother. The page is only destroyed when it exits the stack, so the timing of ngOnInit and ngOnDestroy triggering may not be what you imagine.
Route GuardIonic 3 used to have two hook functions, ionViewCanEnter and ionViewCanLeave, which were used to determine whether a page could be entered/left. They were generally used to restrict access rights or to pop up a secondary confirmation prompt before leaving the editing page. These two functions have been deprecated. Ionic 4 and later use Angular's official routing guard. SummarizeThis is the end of this article about Angular and Ionic life cycle and hook functions. For more relevant Angular Ionic life cycle and hook function content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to view version information in Linux
>>: Tutorial on installing mongodb under linux
How to refresh iframe 1. To refresh, you can use j...
Preface If you use the overflow: scroll attribute...
It is essentially a common js object used to desc...
Nginx cross-domain configuration does not take ef...
This tutorial explains how to verify the IP addre...
<br />Choose the most practical one to talk ...
Preface Merging or splitting by specified charact...
To deploy multiple sites on a server, you need to...
In CSS, text is one of the most common things we ...
The default scroll bar style in Windows is ugly, ...
As more and more Docker images are used, there ne...
Copy code The code is as follows: <!DOCTYPE ht...
The following is the configuration method under c...
<br />Original link: http://www.dudo.org/art...