Components: ng-template inside MatAutocomplete doesn't work

Created on 31 Jan 2020  路  7Comments  路  Source: angular/components

Reproduction

https://stackblitz.com/edit/angular-wwwm2h

Steps to reproduce:

  1. Click on the input field

Expected Behavior

Autocomplete list is rendered on input click

Actual Behavior

Nothing is rendered

If you uncomment extra mat-option then list appears. I think ii's connected with the fact that autocomplete is unable to determine the number of options if they're coming from ng-template

Environment

  • Angular: 8.2.14
  • CDK/Material: 8.2.3
  • Browser(s): any
  • Operating System (e.g. Windows, macOS, Ubuntu): any

All 7 comments

The autocomplete won't open if it doesn't pick up any options usingContentChildren. Projecting them in via ngTemplateOutlet like this isn't supported.

@crisbeto I recently implemented component where used QueryList.changes to track dynamic elements in projected content. Why not use it here as well?

The problem isn't that the content is projected, it's that the content is actually an ng-container which creates the items through a TemplateRef. This case won't be picked up by the QueryList.

so, is it a general Angular problem? Maybe we can address it to Angular team?

It's definitely a framework limitation, but I'm not sure that it's a bug since this is the way it has always worked.

ok, I see. Thanks for explanation

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

theunreal picture theunreal  路  3Comments

jelbourn picture jelbourn  路  3Comments

MurhafSousli picture MurhafSousli  路  3Comments

shlomiassaf picture shlomiassaf  路  3Comments

dzrust picture dzrust  路  3Comments