user3836415
user3836415

Reputation: 982

Generating Components Dynamically (Angular 7) for insertion into a DOM

I need to generate ngx-emoji elements dynamically so that it can be inserted into the dom.

I've generated a hotspot for the insertion, and I'm picking it up by having a reference to it via ViewChild. However, when I try and generate the component via ViewChild it states it is undefined.

I'm following the pattern at https://angular.io/guide/dynamic-component-loader

I've generated a stackblitz for the problem.

EDITED Ok, so it is creating the element but it couldn't be seen on the screen. When you inspect what has been created compared to a component that has been instantiated via the template they look very different.

Upvotes: 0

Views: 58

Answers (1)

user3836415
user3836415

Reputation: 982

Alright, I've resolved this. I needed to add change detection step :

(<EmojiComponent>comp.instance).ngOnChanges();

I'll leave the stackblitz available if anyone is interested.

Upvotes: 1

Related Questions