Leí este hilo creado componente web:
<my-vue-web-comp [userId]="1" id="my-component"></my-vue-web-comp>
Funciona bien en Angular. ¿Cómo puedo detectar cuándo se montó el componente web en DOM?
En este código obtengo nulo:
ngAfterViewInit() { const myComponent = document.getElementById('my-component') console.log(myComponent) //null }
En este código obtengo mi componente, pero debo esperar 0.5 segundos:
ngAfterViewInit() { setTimeout( function() { const myComponent = document.getElementById('my-component') console.log(myComponent) //not null }, 500) }
¿Existe alguna herramienta (evento) para detectar el montaje de componentes web en DOM?
Necesita agregar connectedCallback() de los documentos :
Vue.customElement('web-component', (MyWebComponent as any).options, { connectedCallback() { console.info('connectedCallback', this) }})