I'd like to render custom component inside mat-option. This is the code in my parent component:
<mat-option *ngFor="let option of options" [value]="option.value">
HERE I WOULD LIKE TO INJECT SOME COMPONENT
</mat-option>
Let's assume that I have a component called CustomOptionView:
@Component({
selector: 'custom-option-view',
template: `<h1> {{ label }} </h1>`,
})
export class CustomOptionView{
@Input() label?: string;
}
And I would like to create that component manually in my child component like this:
const factory = this.componentFactoryResolver.resolveComponentFactory(CustomOptionView);
How Can I pass this instance to parent component and render it?
Why I am trying to do that? Because I would like to have options in selectlist that looks differently. One component needs to show icons and multiline text and other doesn't need it. I came to conclusion that I need a set of custom components that I could somehow inject to parent's html.