-1

I am studying how to create a component dynamically in Angular. I can't understand the syntax:

(<AdComponent>componentRef.instance).data = adItem.data;

Can someone explain it?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
M.Nico
  • 1
  • Possible duplicate of [What does enclosing a class in angle brackets "<>" mean in TypeScript?](https://stackoverflow.com/questions/38831342/what-does-enclosing-a-class-in-angle-brackets-mean-in-typescript) – jonrsharpe Sep 06 '18 at 07:25
  • Check out this doc: https://www.typescriptlang.org/docs/handbook/generics.html – J.Ko Apr 09 '20 at 16:08

1 Answers1

0

With this line (<AdComponent>componentRef.instance).data = adItem.data;

In fact you tell to TS the instance is type of AdComponent it's only this.

So in your components who is loaded dynamically the @Input() data is a AdComponent like this

@Input() data:AdComponent
johan pujol
  • 173
  • 2
  • 10