0

With Angular2 RC1 to RC4 if you wanted to get child components which derived from a base class you could do something like:

@Component({    
...
providers: [ provide(BaseComponent,{ useExisting: forwardRef( () => Panel) )}

And your content children property would look like:

@ContentChildren(BaseComponent) allBaseComponents;

I think it was RC5 where 'provide' was depreciated. With 2.0.0 'provide' has been removed. How do we now get child components which have a common base class?

Here is more detail on the RC4 'provide' solution from stackoverflow

Community
  • 1
  • 1

2 Answers2

0

provide(X, { Y }) was replaced with a simple object literal. So instead of calling provide explicitly, just write it like the following:

providers: [
    { provide: BaseComponent, useExisting: forwardRef(() => Panel) }
]

Then, you can still use @ContentChildren with the base component type, just like you are used to.

poke
  • 369,085
  • 72
  • 557
  • 602
-1

What you do is:

@ContentChildren(BaseComponent) allBaseComponents: QueryList<BaseComponent>;

You do not have to provide anything. Notice that allBaseComponents will be available from certain life cycle hook and don't forget to import ContentChildren and QueryList from @angular/core.

Baumi
  • 1,745
  • 1
  • 17
  • 31