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
Before reading this article, it is best to have a...
The mysql 5.7.18 zip version of MySQL is not like...
An absolute URL is used to represent all the conte...
In the table header, you can define the light bor...
This article uses examples to explain the princip...
1. Apache static resource cross-domain access Fin...
Preface vsftp is an easy-to-use and secure ftp se...
1. Install dependency packages yum -y install gcc...
Table of contents 1. Get request: 2. Post request...
The Linux command line provides many commands to ...
Today I want to summarize several very useful HTML...
I believe everyone has used JD. There is a very c...
It mainly shows how to configure X-Frame-Options,...
1. First, download the latest version of MySQL fr...
When installing nginx, mysql, tomcat and other se...