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
1. When to execute setUp We all know that vue3 ca...
I am going to review Java these two days, so I wr...
1. CSS Miscellaneous Icons There are three ways t...
Preface In the Linux kernel, in order to be compa...
This article shares the specific code of js to re...
Environment Introduction: Ubuntu Server 16.04.2+M...
Table of contents Introduction Architecture Advan...
Table of contents 1. Common higher-order function...
1. Object-oriented class inheritance In the above...
1. Basic knowledge (methods of date objects) 😜 ge...
Table of contents background How does element-ui&...
HTML5 adds a native placeholder attribute for inp...
Using iframes can easily call pages from other we...
Recently, due to business adjustments in the comp...
symptom I set a crontab task on a centos7 host, b...