Should I apply template in the constructor or connectedCallback of a custom element? In my experience, when I apply it in connectedCallback, sometimes attributeChangedCallback is called before and I can't query for elements.
export class TestElement extends HTMLElement {
constructor() {
super();
//apply template here ?
}
connectedCallback() {
//apply template here ?
}
}
I'm curious to understand where and why it's better to apply the template.
Here is an example snippet of applying the template:
let t = document.createElement('template');
t.innerHTML = require('template.html');
this.appendChild(t.content.cloneNode(true));