0

let say i have a variable in a component, MyVar.

I want to give to this variable a component type:

 MyVar = MyComponentType.

MyComponentType comes from a Json String or a simple String 'MyComponentType'. How can i do that?

The Hungry Dictator
  • 3,444
  • 5
  • 37
  • 53
Amir Nadji
  • 21
  • 1
  • 3
  • See http://stackoverflow.com/questions/36325212/angular-2-dynamic-tabs-with-user-click-chosen-components/36325468#36325468 for a similar question. – Günter Zöchbauer Apr 18 '17 at 09:15
  • What do you mean by a "variable in a component". Do you mean a property? If I understand what you are trying to do, the usual approach is to write a "factory". –  Apr 18 '17 at 12:25
  • [How to get a component type in Angular 2](http://stackoverflow.com/questions/36411267/how-to-get-a-component-type-in-angular-2-related-to-dynamiccomponentloader) | [How do I initialize a typescript object with a JSON object](http://stackoverflow.com/questions/22885995/how-do-i-initialize-a-typescript-object-with-a-json-object) – VikingCode Apr 18 '17 at 12:47
  • 'MyComponentType' is a string comming from a Json.I already have a component Named MyComponentType. I try to find a solution to give to the ngComponentOutlet a component witch the name is the same as the 'MyComponentType' . I don't know witch value will come from the Json so i have to transfom the Json string 'MyComponentType to a an exisiting component MyComponentType and then bind it to the ngComponentOutlet. Thank you – Amir Nadji Apr 18 '17 at 15:18

0 Answers0