I am trying to display items in dropdown using ng-select in Angular 5. But the dropdown component that I am designing should be more generic in nature meaning people who are calling my dropdown should be able to pass customized template for displaying items in dropdown. i.e. the items list in dropdown should be build with specific template and a call to my generic dropdown should display the customized list of items. Is this something that can be achieved in transclusion? Currently I am using "dropdownVal" which is of String[] datatype but instead I need to have array of template/component.
My code is below
dropdown.component.ts
@Component({
selector: 'wdsk-dropdown',
templateUrl: './dropdown.component.html',
styleUrls: ['./dropdown.component.scss']
})
export class DropdownComponent implements OnInit {
@Input() dropdownVal: string[];
@Input() placeholder: string;
@Output() selectedItem = new EventEmitter();
constructor() { }
ngOnInit() {
}
onSelect(value: any) {
this.selectedItem.emit(value);
}
}
Template - dropdown.component.html
<div class="col-md-12 account-dropdown">
<div class="form-group row">
<div class="col-md-12">
<ngx-select tabindex="0" placeholder={{placeholder}} [items]="dropdownVal" (selected)="onSelect($event)">
</ngx-select>
</div>
</div>
</div>
<ng-content></ng-content>inside the dropdown.component.html wherever you want the customised content to display, and pass whatever you want to display inside thewdsk-dropdowntags