Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

200
Views
Angular using ngTemplateOutlet for a custom select dropdown

I'm trying to create a custom select dropdown component that can be easily implemented by other devs in the following way:

<ui-select placeholder="select an option" label="Select">
  <ui-select-option *ngFor="let option of options" [id]="option">
    <!-- any custom content to display for the option -->
  </ui-select-option>
</ui-select>

I am using @ContentChildren along with ngTemplateOutlet to project each option into the options list (this allows me to wrap each option in a list item which can handle click events/selected css state etc.).

This is all working fine, however when I select an option, I want the template from the selected option to populate in the select input box. When I do this, the option magically disappears from the list.

I've created a minimal reproduction on stackblitz (https://stackblitz.com/edit/angular-ackvfp).

I've found a way that works with structural directives (https://stackblitz.com/edit/templateref-to-multiple-outlets), however I was hoping to avoid this, since to loop a bunch of options and render them would require an additional ng-container for the loop, since only one directive can exist on each component (would end up looking like the below):

<ui-select placeholder="select an option" label="Select">
  <ng-container *ngFor="let option of options">
    <ui-select-option *myValue="option">
      <!-- any custom content to display for the option -->
    </ui-select-option>
  </ng-container>
</ui-select>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!