a function is passing the name of my component via a string but I need it to be the actual component class:
Current: "MyComponent" Need: MyComponent
I need to "convert" it so It's passing correctly. I have an ngFor
that spits out values and I'm trying to use piping to convert it:
<div id="grid">
<gridster [options]="options">
<gridster-item [item]="item" *ngFor="let item of dashboard;let i = index;">
<div class="grid-header drag-handle">
<span class="handle-icon"><i class="material-icons">open_with</i></span>
<span class="close-icon" (click)="removePanel(item)"><i class="material-icons">close</i></span>
</div>
<div class="grid-content">
<ndc-dynamic [ndcDynamicComponent]="item.viewType | dynamicComponent"></ndc-dynamic>
</div>
</gridster-item>
</gridster>
</div>
Above it's item.viewType
that's a strong coming from my item array. I'm passing the value to a dynamicComponent
custom pipe. I have my components imported into my dynamic-component.pipe.ts
. I just need to change the string to the specified viewType
and return the typed
value:
import { Pipe, PipeTransform } from '@angular/core';
//pulling in all the possible components
import * from '../../views';
@Pipe({
name: 'dynamicComponent'
})
export class DynamicComponentPipe implements PipeTransform {
transform(value: string): any {
}
}