Aurelia Components Lifecycle

In the last article, we tackled Aurelia components. This time, we will talk about the Aurelia components lifecycle.

Aurelia offers different lifecycle methods to manipulate components. The following methods are implemented on your view-model to enact these methods.

  • Constructor() Initializing objects within a class is the main purpose of constructor(). Without this method, a default constructor will be used.
  • Created(owningView, myView)When view-model and view are connected to a controller, this method is invoked next. And then two arguments will be received. First the owningView is the view declared inside of a component. myView is passed second when the component itself has a view of its own.
  • Bind(bindingContext,overrideContext)the view-model activates databinding when the bind method is invoked. The binding context is responsible for which component is being bound first and then override context will contain the additional context properties if the user wants to. 
  • Attached()Then if the user calls an attached method the component will be connected to the DOM.
  • Detached()If the user wants otherwise, the detached method is called to remove a component to a DOM.
  • Unbind()Unbind is also a reverse like the detached method. It unbinds a component to the view-model. But usually when detached method is called its already unbound.

These methods are shown in the order they are meant to be used. Bind is always invoked first to ensure the elements have taken their initial state before attaching them to a DOM.

aurelia components

But using these methods are fully optional. They are designed just to enable the user to have a full control of your Aurelia components.

On the next tutorial article, we will discuss Aurelia’s template system.

Subscribe Now and Upgrade Your Skills Today!
Sign up now and have the latest tech tutorials delivered straight to your mailbox.

PLUS: Get exclusive member-only discounts (up to 80% OFF!!) on our top tech courses in Udemy!
We hate spam. Your email address will not be sold or shared with anyone else.