components icon indicating copy to clipboard operation
components copied to clipboard

cdkVirtualFor does not work in ng-content

Open vthinkxie opened this issue 7 years ago • 11 comments

What is the expected behavior?

when *cdkVirtualFor in ng-content, and cdk-virtual-scroll-viewport in parent component, everything works fine.

What is the current behavior?

when *cdkVirtualFor in ng-content, and cdk-virtual-scroll-viewport in parent component, error happend

ERROR
Error: StaticInjectorError(AppModule)[CdkScrollable -> CdkVirtualScrollViewport]: 
StaticInjectorError(Platform: core)[CdkScrollable -> CdkVirtualScrollViewport]: 
NullInjectorError: No provider for CdkVirtualScrollViewport!

What are the steps to reproduce?

Providing a StackBlitz reproduction is the best way to share your issue.

https://stackblitz.com/edit/angular-oqcthb?file=src/app/app.component.html

Which versions of Angular, Material, OS, TypeScript, browsers are affected?

Is there anything else we should know?

vthinkxie avatar Feb 22 '19 10:02 vthinkxie

Any news on this ?

Yea any news?

gigalala avatar Aug 09 '19 17:08 gigalala

Any News ??

maximcoding avatar Aug 13 '19 11:08 maximcoding

Same issue

xpleria avatar Nov 18 '19 17:11 xpleria

Any news?

slarrieu avatar Dec 03 '19 13:12 slarrieu

Any news ?

WaffleBuffer avatar Apr 23 '20 07:04 WaffleBuffer

any news?

MiroKov avatar May 13 '20 06:05 MiroKov

Any updates? Same issue..

jeetparikh avatar May 24 '20 05:05 jeetparikh

This is a limitation of Angular's content projection. https://github.com/angular/angular/issues/37319 has been filed to hopefully improve some of the short-comings

mmalerba avatar May 28 '20 16:05 mmalerba

Here is a working example of the above provided stackblitz. It's not 100% but should provide a somewhat feasable strategy.

  • The VirtualForDirective provides the template used for stamping out items.
  • The VirtualForDirective provides a reference (viewContainerRef), later used to replace content.
  • The VirtualScrollViewportComponent provides a wrapper containing the real CDK scrolling.
  • The HelloComponent uses AfterContentInit to get a hold of VirtualForDirective and attaches it to the viewport.

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

eddietisma avatar Jun 18 '20 12:06 eddietisma

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.