Managing a component's life cycle
As we said earlier, Aurelia provides very complete life cycle event methods to customize and improve the behavior of our application. Here's a list with these methods:
export class ComponentLifecycleExample { retrievedData; constructor(service) { // Create and initialize your class object here... this.service = service; } created(owningView, myView) { // Invoked once the component is created... } bind(bindingContext, overrideContext) { // Invoked once the databinding is activated... } attached(argument) { // Invoked once the component is attached to the DOM... this.retrievedData = this.service.getData(); } detached(argument) { // Invoked when component is detached from the dom this.retrievedData = null; } unbind(argument) { // Invoked when component is unbound... } }
Let's explore each method presented in the script:
constructor()
: This is the firstmethod that is called. It's used to set all view model dependencies and values required for its...