Questions about Angular Dynamic Components, an Angular technique for creating components during runtime. Use this tag for questions which are not specific to an individual version of Angular.
Questions tagged [angular-dynamic-components]
203 questions
11
votes
2 answers
When is OnInit event triggered for a dynamically loaded angular component?
I am dynamically loading an Angular component (MyComponent) with the following code. I am also passing some data to the component after creating it.
let componentFactory =…

Sarath S Menon
- 2,168
- 1
- 16
- 21
7
votes
1 answer
How to remove a component dynamically in angular
I went through angular dynamically loading components. But i could not find how to remove the component dynamically.
My requirement is that the chat application loads dynamic component(image/graph/list/table) as per the conversation. But how can i…

Sridhar Natuva
- 211
- 1
- 4
- 16
6
votes
1 answer
How to dynamically add component to another component in service
I would dynamically component to another component in the service , Firstly inside the service factory both components and I created the component with access to ViewContainer. But the component cannot be create !
Service :
@Injectable({
…

Allahyar
- 209
- 4
- 16
6
votes
2 answers
Angular Dynamic Components: @ViewChildren get ViewContainerRef for every component in QueryList
I am building a dialog with dynamic tabs that can receive a component to be placed in the tab body. I am having a hard time creating multiple dynamic components using @ViewChildren. I have successfully done this with a single component and…

CAlex
- 1,140
- 2
- 14
- 28
6
votes
1 answer
How to dynamically add angular components to the DOM without a pre-determined ViewContainerRef?
This is a solution I found that I think will be useful to others.
This can be applied to any native element that does not have a ViewContainerRef set on it.
I am trying to implant an angular component inside a table (Tabulator v4.2) on a click…

Yotam
- 97
- 7
6
votes
2 answers
Emit event from dynamically created child component to parent component
I have a slider in which are dynamically created items - these are child components.
Parent template where is ng-container for slider:

rusna
- 366
- 6
- 20
6
votes
1 answer
Angular lags performance if multiple DOM elements inserted via dynamic component with binding
I have created n-level nested expand/collapse functionality using dynamic components of angular 5.
Functionally everything is working fine but when I load multiple dom elements browser either crashes or scroll stops working (Jerky Scroll)
Basically…

Ripul Chhabra
- 234
- 2
- 17
6
votes
4 answers
Angular - Dynamic component in mat-tab
I have a mat-tab-group (angular material) and I want to be able to add from code behind mat-tabs including other components. I am using ComponentFactoryResolver to create the component but I am not able to add the new component to the new mat-tab…

stathis ts
- 61
- 1
- 3
5
votes
1 answer
select angular template in component function instead of adding in @Component
I am working in angular 8, i have a component for which i have around 6 or more templates. user will select from interface or some logic that which one to use, let say,
if(a==2) use template 'ddd.html'
else user template 'sss.html'
I don't want to…

Muhammad Aadil Banaras
- 1,134
- 1
- 11
- 21
5
votes
1 answer
ngOnInit is not called on dynamic component
I'm using Angular 8 for a project, and I'm having trouble launching a dynamic component because ngOnInit doesn't get called. I've build a directive called PlaceholderDirective, shown below:
@Directive({
selector: '[appPlaceholder]'
})
export class…

codehero
- 499
- 3
- 15
5
votes
2 answers
Using a generic Component with resolveComponentFactory result in Component<{}> instead of
I have build a dialog service which dynamically create a DialogComponent with a child component.
I want my DialogComponent to be a generic class of since i wish to type for whatever component child i'm using. I'm currently create my…

Pilouk
- 1,267
- 1
- 18
- 36
5
votes
1 answer
Why Angular requires us to declare dynamic components in declarations array and entryComponents array?
I was implementing dynamic components for one of my project. The concept of dynamic components is that they come into the memory once they are needed and they have no reference in any template.
According to the official docs we declare such…

patrick.1729
- 4,222
- 2
- 20
- 29
5
votes
2 answers
How to use reactive forms in a dynamic component
BackgroundI receive client generated data from the server that contains HTML that I then use to create a dynamic component that gets injected and displayed in our client. The HTML I receive can contain one or many inputs that I need to bind to via…

Narm
- 10,677
- 5
- 41
- 54
4
votes
0 answers
How to project a Component into another Component and pass the result to ng-boostrap's NgbModal.open(content)
I'm trying to make a very simple wrapper around the ng-bootstrap modal service. ng-bootstrap's modal service has an open(content) method that takes in a TemplateRef or a component class meant to be the content of the modal.
What I want is to make my…

snowfrogdev
- 5,963
- 3
- 31
- 58
4
votes
1 answer
Angular - Dynamic Component Rendering Wrong Data
Solved
As mentioned below by Aaron, the "Other Option" approach works without issues and feels a lot cleaner. I'll leave the updates and everything in case anyone in the future has a similar problem and the workarounds provide useful somehow.
I'm…

iEquivalent
- 73
- 5