When should I apply template in constructor or connectedCallback

Viewed 645

When should I apply template in constructor or connectedCallback ? When I do it in callback sometimes attributeChangedCallback is called before and i can't query for elements.

export class TestElement extends HTMLElement {
  constructor() {
    super();
    //here ?
  }

  connectedCallback() {
    //here ?
  }
}

I would like to know where and why it is better.

Here is a snipped of template apply code

let t = document.createElement('template');
t.innerHTML = require('template.html');
this.appendChild(t.content.cloneNode(true));
1 Answers
Related