Explain Component Lifecycle of Aurelia
Components in the Ionic framework follow a specific lifecycle, and there are several methods available to implement on the view-model to connect with this lifecycle.
- Constructor (): This method is used to initialize an object created with a class. The view-model’s constructor is called first.
- Created (owningView: View, myView: View): If the view-model implements the created callback, it is invoked next. At this point in time, the view has also been created and both the view-model and the view are connected to their controller. The created callback will receive the instance of the “owningView”. This is the view that the component is declared inside of. If the component itself has a view, this will be passed second.
- Attached (): The component is attached to the DOM. If the view-model has an attached callback, it will be invoked at this time.
- Detached (): This method is called when the View is detached from the DOM. The component may be removed from the DOM. If/When this happens, and if the view-model has a detached callback, this is when it will be invoked.
- Bind (bindingContext: Object, overrideContext: Object): This method happens after binding occurs but before the DOM attachment. This is where the Databinding engine binds the contents of the View.
- Unbind (): After a component is detached, it’s usually unbound. If your view-model has the unbind callback, it will be invoked during this process.
