Reputation: 6812
I have two Angular 2 components, <future-todos>
and <past-todos>
. Can I somehow load them dynamically as shown below?
component.ts
if (condition) {
list = 'future';
} else {
list = 'past';
}
component.html
<{{list}}-todos></{{list}}-todos>
My actual situation is more complex, and I've omitted a lot of code to simplify this example showing my needs.
Upvotes: 1
Views: 202
Reputation: 6812
Short answer: No.
But NgSwitch
can be used in this case:
HTML:
<div [ngSwitch]="list">
<div *ngSwitchCase="future">
<future-todos></future-todos>
</div>
<div *ngSwitchCase="past">
<past-todos></past-todos>
</div>
<div *ngSwitchDefault>Unrecognized list type</div>
</div>
Don't forget the default type
Upvotes: 1